Author: Braulio Bhavamitra <braulio@prout.io>
plugin/manager: don't call method if not defined on plugin plugin/manager: call default as fallback
config/spring.rb | 2 +- lib/noosfero/plugin/manager.rb | 22 ++++++++++------------
diff --git a/config/spring.rb b/config/spring.rb index d008a3ef2dbbd86e79f58b6479fd9b912139bf67..f0bcfd0a8968314f9de328d558422683560dd84a 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -3,7 +3,7 @@ .env .env.local .ruby-version .rbenv-vars - lib + lib/** tmp/restart.txt tmp/caching-dev.txt db/migrate diff --git a/lib/noosfero/plugin/manager.rb b/lib/noosfero/plugin/manager.rb index e1ac12634f2928e97a09af55efa5eeda4cb9bd04..e11b9581696f06f4cba66f5d0cda3f610af08277 100644 --- a/lib/noosfero/plugin/manager.rb +++ b/lib/noosfero/plugin/manager.rb @@ -34,25 +34,23 @@ alias :dispatch_scopes :dispatch_without_flatten def dispatch_first(event, *args) - default = Noosfero::Plugin.new.send(event, *args) - result = default each do |plugin| - result = plugin.send(event, *args) - break if result != default + method = plugin.method event + next unless method.owner == plugin.class + return method.call(*args) end - result + Noosfero::Plugin.new.send event, *args end def fetch_first_plugin(event, *args) - default = Noosfero::Plugin.new.send(event, *args) - result = nil + default = Noosfero::Plugin.new.send event, *args each do |plugin| - if plugin.send(event, *args) != default - result = plugin.class - break - end + method = plugin.method event + next unless method.owner == plugin.class + next unless method.call(*args) != default + return plugin.class end - result + nil end def pipeline(event, *args)