Commit d0770e1d99111001f5d39beb8543bc63c8a3dae5
1 parent
babeaf01
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
added hook to plugins define grape api routes
Showing
3 changed files
with
26 additions
and
0 deletions
Show diff stats
Rakefile
@@ -14,3 +14,15 @@ require 'tasks/rails' | @@ -14,3 +14,15 @@ require 'tasks/rails' | ||
14 | plugins_tasks = Dir.glob("config/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort + | 14 | plugins_tasks = Dir.glob("config/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort + |
15 | Dir.glob("config/plugins/*/vendor/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort | 15 | Dir.glob("config/plugins/*/vendor/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort |
16 | plugins_tasks.each{ |ext| load ext } | 16 | plugins_tasks.each{ |ext| load ext } |
17 | + | ||
18 | + | ||
19 | +desc "Print out grape routes" | ||
20 | +task :grape_routes => :environment do | ||
21 | + #require 'api/api.rb' | ||
22 | + API::API.routes.each do |route| | ||
23 | + puts route | ||
24 | + method = route.route_method | ||
25 | + path = route.route_path | ||
26 | + puts " #{method} #{path}" | ||
27 | + end | ||
28 | +end |
lib/api/api.rb
@@ -19,5 +19,15 @@ module API | @@ -19,5 +19,15 @@ module API | ||
19 | mount V1::Categories | 19 | mount V1::Categories |
20 | mount Session | 20 | mount Session |
21 | 21 | ||
22 | + # hook point which allow plugins to add Grape::API extensions to API::API | ||
23 | + #finds for plugins which has api mount points classes defined (the class should extends Grape::API) | ||
24 | + @plugins = Noosfero::Plugin.all.map { |p| p.constantize } | ||
25 | + @plugins.each do |klass| | ||
26 | + if klass.public_methods.include? 'api_mount_points' | ||
27 | + klass.api_mount_points.each do |mount_class| | ||
28 | + mount mount_class if mount_class && ( mount_class < Grape::API ) | ||
29 | + end | ||
30 | + end | ||
31 | + end | ||
22 | end | 32 | end |
23 | end | 33 | end |
lib/noosfero/plugin.rb
@@ -116,6 +116,10 @@ class Noosfero::Plugin | @@ -116,6 +116,10 @@ class Noosfero::Plugin | ||
116 | def has_admin_url? | 116 | def has_admin_url? |
117 | File.exists?(File.join(root_path, 'controllers', "#{name.underscore}_admin_controller.rb")) | 117 | File.exists?(File.join(root_path, 'controllers', "#{name.underscore}_admin_controller.rb")) |
118 | end | 118 | end |
119 | + | ||
120 | + # -> define grape class used to map resource api provided by the plugin | ||
121 | + def api_mount_points | ||
122 | + end | ||
119 | end | 123 | end |
120 | 124 | ||
121 | def expanded_template(file_path, locals = {}) | 125 | def expanded_template(file_path, locals = {}) |