Commit bb5134e1b94445c381761623b23e37175410717c

Authored by Rodrigo Souto
1 parent dee13924

[macro-support-review] Renaming manager first to dispatch_first

Also renaming dispatch_plugins to fetch_plugins and first_plugin to
fetch_first_plugin
app/controllers/application_controller.rb
@@ -178,7 +178,7 @@ class ApplicationController < ActionController::Base @@ -178,7 +178,7 @@ class ApplicationController < ActionController::Base
178 def find_by_contents(asset, scope, query, paginate_options={:page => 1}, options={}) 178 def find_by_contents(asset, scope, query, paginate_options={:page => 1}, options={})
179 scope = scope.send(options[:filter]) if options[:filter] 179 scope = scope.send(options[:filter]) if options[:filter]
180 180
181 - @plugins.first(:find_by_contents, asset, scope, query, paginate_options, options) || 181 + @plugins.dispatch_first(:find_by_contents, asset, scope, query, paginate_options, options) ||
182 fallback_find_by_contents(asset, scope, query, paginate_options, options) 182 fallback_find_by_contents(asset, scope, query, paginate_options, options)
183 end 183 end
184 184
app/controllers/public/content_viewer_controller.rb
@@ -98,7 +98,7 @@ class ContentViewerController < ApplicationController @@ -98,7 +98,7 @@ class ContentViewerController < ApplicationController
98 session[:notice] = _("Notification of new comments to '%s' was successfully canceled") % params[:email] 98 session[:notice] = _("Notification of new comments to '%s' was successfully canceled") % params[:email]
99 end 99 end
100 end 100 end
101 - 101 +
102 @comments = @plugins.dispatch_first(:load_comments, @page) 102 @comments = @plugins.dispatch_first(:load_comments, @page)
103 @comments ||= @page.comments.without_spam.as_thread 103 @comments ||= @page.comments.without_spam.as_thread
104 @comments = [@comments] unless @comments.is_a?(Array) 104 @comments = [@comments] unless @comments.is_a?(Array)
lib/noosfero/plugin/manager.rb
@@ -24,7 +24,7 @@ class Noosfero::Plugin::Manager @@ -24,7 +24,7 @@ class Noosfero::Plugin::Manager
24 dispatch_without_flatten(event, *args).flatten 24 dispatch_without_flatten(event, *args).flatten
25 end 25 end
26 26
27 - def dispatch_plugins(event, *args) 27 + def fetch_plugins(event, *args)
28 map { |plugin| plugin.class if plugin.send(event, *args) }.compact.flatten 28 map { |plugin| plugin.class if plugin.send(event, *args) }.compact.flatten
29 end 29 end
30 30
@@ -32,18 +32,9 @@ class Noosfero::Plugin::Manager @@ -32,18 +32,9 @@ class Noosfero::Plugin::Manager
32 map { |plugin| plugin.send(event, *args) }.compact 32 map { |plugin| plugin.send(event, *args) }.compact
33 end 33 end
34 34
35 - def dispatch_first(event, *args)  
36 - value = nil  
37 - map do |plugin|  
38 - value = plugin.send(event, *args)  
39 - break if value  
40 - end  
41 - value  
42 - end  
43 -  
44 alias :dispatch_scopes :dispatch_without_flatten 35 alias :dispatch_scopes :dispatch_without_flatten
45 36
46 - def first(event, *args) 37 + def dispatch_first(event, *args)
47 result = nil 38 result = nil
48 each do |plugin| 39 each do |plugin|
49 result = plugin.send(event, *args) 40 result = plugin.send(event, *args)
@@ -52,7 +43,7 @@ class Noosfero::Plugin::Manager @@ -52,7 +43,7 @@ class Noosfero::Plugin::Manager
52 result 43 result
53 end 44 end
54 45
55 - def first_plugin(event, *args) 46 + def fetch_first_plugin(event, *args)
56 result = nil 47 result = nil
57 each do |plugin| 48 each do |plugin|
58 if plugin.send(event, *args) 49 if plugin.send(event, *args)
test/unit/plugin_manager_test.rb
@@ -135,7 +135,7 @@ class PluginManagerTest < ActiveSupport::TestCase @@ -135,7 +135,7 @@ class PluginManagerTest < ActiveSupport::TestCase
135 environment.enable_plugin(Plugin2.name) 135 environment.enable_plugin(Plugin2.name)
136 environment.enable_plugin(Plugin3.name) 136 environment.enable_plugin(Plugin3.name)
137 137
138 - results = manager.dispatch_plugins(:random_event) 138 + results = manager.fetch_plugins(:random_event)
139 139
140 assert_includes results, Plugin2 140 assert_includes results, Plugin2
141 assert_includes results, Plugin3 141 assert_includes results, Plugin3
@@ -165,35 +165,7 @@ class PluginManagerTest < ActiveSupport::TestCase @@ -165,35 +165,7 @@ class PluginManagerTest < ActiveSupport::TestCase
165 165
166 Plugin3.any_instance.expects(:random_event).never 166 Plugin3.any_instance.expects(:random_event).never
167 167
168 - assert_equal Plugin2, manager.first_plugin(:random_event)  
169 - end  
170 -  
171 - should 'dispatch_first method returns the first plugin response if there is many plugins to responde the event and the first one respond nil' do  
172 -  
173 - class Plugin1 < Noosfero::Plugin  
174 - def random_event  
175 - nil  
176 - end  
177 - end  
178 -  
179 - class Plugin2 < Noosfero::Plugin  
180 - def random_event  
181 - 'Plugin 2 action.'  
182 - end  
183 - end  
184 -  
185 - class Plugin3 < Noosfero::Plugin  
186 - def random_event  
187 - 'Plugin 3 action.'  
188 - end  
189 - end  
190 -  
191 - environment.stubs(:enabled_plugins).returns([Plugin1.to_s, Plugin2.to_s, Plugin3.to_s])  
192 -  
193 - p2 = Plugin2.new  
194 -  
195 - assert_equal p2.random_event, plugins.dispatch_first(:random_event) 168 + assert_equal Plugin2, manager.fetch_first_plugin(:random_event)
196 end 169 end
197 170
198 end 171 end
199 -