Commit d32bf3a4a0fd628281f086f68243c664f15e126c
1 parent
3e99a558
Exists in
master
and in
26 other branches
Revert "plugins: only call event on plugin if it is defined"
This reverts commit da84575ee29154fa4f24c9acdfce9ec16a7acb5b.
Showing
2 changed files
with
7 additions
and
39 deletions
Show diff stats
lib/noosfero/plugin/manager.rb
... | ... | @@ -20,15 +20,15 @@ class Noosfero::Plugin::Manager |
20 | 20 | # return [1,0,1,2,3] |
21 | 21 | # |
22 | 22 | def dispatch(event, *args) |
23 | - flat_map{ |plugin| result_for plugin, event, *args }.compact | |
23 | + dispatch_without_flatten(event, *args).flatten | |
24 | 24 | end |
25 | 25 | |
26 | 26 | def fetch_plugins(event, *args) |
27 | - map { |plugin| plugin.class if result_for plugin, event, *args }.compact.flatten | |
27 | + map { |plugin| plugin.class if plugin.send(event, *args) }.compact.flatten | |
28 | 28 | end |
29 | 29 | |
30 | 30 | def dispatch_without_flatten(event, *args) |
31 | - map { |plugin| result_for plugin, event, *args }.compact | |
31 | + map { |plugin| plugin.send(event, *args) }.compact | |
32 | 32 | end |
33 | 33 | |
34 | 34 | alias :dispatch_scopes :dispatch_without_flatten |
... | ... | @@ -37,14 +37,9 @@ class Noosfero::Plugin::Manager |
37 | 37 | Noosfero::Plugin.new.send event, *args |
38 | 38 | end |
39 | 39 | |
40 | - def result_for plugin, event, *args | |
41 | - method = plugin.method event | |
42 | - method.call *args if method.owner != Noosfero::Plugin | |
43 | - end | |
44 | - | |
45 | 40 | def dispatch_first(event, *args) |
46 | 41 | each do |plugin| |
47 | - result = result_for plugin, event, *args | |
42 | + result = plugin.send(event, *args) | |
48 | 43 | return result if result.present? |
49 | 44 | end |
50 | 45 | default_for event, *args |
... | ... | @@ -52,7 +47,7 @@ class Noosfero::Plugin::Manager |
52 | 47 | |
53 | 48 | def fetch_first_plugin(event, *args) |
54 | 49 | each do |plugin| |
55 | - result = result_for plugin, event, *args | |
50 | + result = plugin.send event, *args | |
56 | 51 | return plugin.class if result.present? |
57 | 52 | end |
58 | 53 | nil |
... | ... | @@ -60,7 +55,7 @@ class Noosfero::Plugin::Manager |
60 | 55 | |
61 | 56 | def pipeline(event, *args) |
62 | 57 | each do |plugin| |
63 | - result = result_for plugin, event, *args | |
58 | + result = plugin.send(event, *args) | |
64 | 59 | result = result.kind_of?(Array) ? result : [result] |
65 | 60 | raise ArgumentError, "Pipeline broken by #{plugin.class.name} on #{event} with #{result.length} arguments instead of #{args.length}." if result.length != args.length |
66 | 61 | args = result |
... | ... | @@ -69,7 +64,7 @@ class Noosfero::Plugin::Manager |
69 | 64 | end |
70 | 65 | |
71 | 66 | def filter(property, data) |
72 | - inject(data){ |data, plugin| data = plugin.send(property, data) } | |
67 | + inject(data) {|data, plugin| data = plugin.send(property, data)} | |
73 | 68 | end |
74 | 69 | |
75 | 70 | def parse_macro(macro_name, macro, source = nil) | ... | ... |
test/unit/plugin_manager_test.rb
... | ... | @@ -304,31 +304,4 @@ class PluginManagerTest < ActiveSupport::TestCase |
304 | 304 | @manager.dispatch_first :find_by_contents, :products, environment.products, 'product' |
305 | 305 | end |
306 | 306 | |
307 | - should 'not event if it is not defined by plugin' do | |
308 | - class Noosfero::Plugin | |
309 | - def never_call | |
310 | - nil | |
311 | - end | |
312 | - end | |
313 | - class Plugin1 < Noosfero::Plugin | |
314 | - def never_call | |
315 | - 'defined' | |
316 | - end | |
317 | - end | |
318 | - class Plugin2 < Noosfero::Plugin | |
319 | - end | |
320 | - Noosfero::Plugin.stubs(:all).returns(['PluginManagerTest::Plugin1', 'PluginManagerTest::Plugin2']) | |
321 | - environment.enable_plugin(Plugin1) | |
322 | - environment.enable_plugin(Plugin2) | |
323 | - plugin1 = @manager.enabled_plugins.detect{ |p| p.is_a? Plugin1 } | |
324 | - plugin2 = @manager.enabled_plugins.detect{ |p| p.is_a? Plugin2 } | |
325 | - | |
326 | - assert_equal Plugin1, Plugin1.new.method(:never_call).owner | |
327 | - assert_equal Noosfero::Plugin, Plugin2.new.method(:never_call).owner | |
328 | - # expects never can't be used as it defines the method | |
329 | - @manager.expects(:result_for).with(plugin1, :never_call).returns(Plugin1.new.never_call) | |
330 | - @manager.expects(:result_for).with(plugin2, :never_call).returns(nil) | |
331 | - @manager.dispatch :never_call | |
332 | - end | |
333 | - | |
334 | 307 | end | ... | ... |