Commit d0770e1d99111001f5d39beb8543bc63c8a3dae5

Authored by Ábner Silva de Oliveira
1 parent babeaf01

added hook to plugins define grape api routes

Rakefile
... ... @@ -14,3 +14,15 @@ require 'tasks/rails'
14 14 plugins_tasks = Dir.glob("config/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort +
15 15 Dir.glob("config/plugins/*/vendor/plugins/*/{tasks,lib/tasks,rails/tasks}/**/*.rake").sort
16 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 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
... ... @@ -116,6 +116,10 @@ class Noosfero::Plugin
116 116 def has_admin_url?
117 117 File.exists?(File.join(root_path, 'controllers', "#{name.underscore}_admin_controller.rb"))
118 118 end
  119 +
  120 + # -> define grape class used to map resource api provided by the plugin
  121 + def api_mount_points
  122 + end
119 123 end
120 124  
121 125 def expanded_template(file_path, locals = {})
... ...