Commit df13e6de77e7777dd15b8e8a565e006dc7c000c1
Committed by
Rodrigo Souto
1 parent
9074ef53
Exists in
master
and in
29 other branches
added hook to plugins define grape api routes
Showing
3 changed files
with
31 additions
and
0 deletions
Show diff stats
Rakefile
| ... | ... | @@ -15,4 +15,21 @@ Noosfero::Application.load_tasks |
| 15 | 15 | Dir.glob(pattern).sort |
| 16 | 16 | end.flatten.each do |taskfile| |
| 17 | 17 | load taskfile |
| 18 | +end | |
| 19 | + | |
| 20 | +# plugins' tasks | |
| 21 | +plugins_tasks = Dir.glob("config/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort + | |
| 22 | + Dir.glob("config/plugins/*/vendor/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort | |
| 23 | +plugins_tasks.each{ |ext| load ext } | |
| 24 | + | |
| 25 | + | |
| 26 | +desc "Print out grape routes" | |
| 27 | +task :grape_routes => :environment do | |
| 28 | + #require 'api/api.rb' | |
| 29 | + API::API.routes.each do |route| | |
| 30 | + puts route | |
| 31 | + method = route.route_method | |
| 32 | + path = route.route_path | |
| 33 | + puts " #{method} #{path}" | |
| 34 | + end | |
| 18 | 35 | end | ... | ... |
lib/api/api.rb
| ... | ... | @@ -19,5 +19,15 @@ module API |
| 19 | 19 | mount V1::Categories |
| 20 | 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 | 32 | end |
| 23 | 33 | end | ... | ... |
lib/noosfero/plugin.rb
| ... | ... | @@ -200,6 +200,10 @@ class Noosfero::Plugin |
| 200 | 200 | def has_admin_url? |
| 201 | 201 | File.exists?(File.join(root_path, 'controllers', "#{name.underscore}_admin_controller.rb")) |
| 202 | 202 | end |
| 203 | + | |
| 204 | + # -> define grape class used to map resource api provided by the plugin | |
| 205 | + def api_mount_points | |
| 206 | + end | |
| 203 | 207 | end |
| 204 | 208 | |
| 205 | 209 | def expanded_template(file_path, locals = {}) | ... | ... |