Commit 2572302ae85ec0d4aee7e663a03b8b6844f10ee6
1 parent
6b50d1d9
Exists in
master
and in
29 other branches
plugins: fix hotspot for around_filter
Around filter need to yield if the plugin is not enabled and need to receive a block from the controller
Showing
2 changed files
with
9 additions
and
4 deletions
Show diff stats
lib/noosfero/plugin.rb
@@ -138,11 +138,12 @@ class Noosfero::Plugin | @@ -138,11 +138,12 @@ class Noosfero::Plugin | ||
138 | filters = [filters] | 138 | filters = [filters] |
139 | end | 139 | end |
140 | filters.each do |plugin_filter| | 140 | filters.each do |plugin_filter| |
141 | + plugin_filter[:options] ||= {} | ||
142 | + plugin_filter[:options][:if] = -> { environment.plugin_enabled? plugin.module_name } | ||
143 | + | ||
141 | filter_method = "#{plugin.identifier}_#{plugin_filter[:method_name]}".to_sym | 144 | filter_method = "#{plugin.identifier}_#{plugin_filter[:method_name]}".to_sym |
142 | - controller_class.send(plugin_filter[:type], filter_method, (plugin_filter[:options] || {})) | ||
143 | - controller_class.send(:define_method, filter_method) do | ||
144 | - instance_exec(&plugin_filter[:block]) if environment.plugin_enabled?(plugin) | ||
145 | - end | 145 | + controller_class.send plugin_filter[:type], filter_method, plugin_filter[:options] |
146 | + controller_class.send :define_method, filter_method, &plugin_filter[:block] | ||
146 | end | 147 | end |
147 | end | 148 | end |
148 | 149 |
lib/noosfero/plugin/parent_methods.rb
@@ -11,6 +11,10 @@ class Noosfero::Plugin | @@ -11,6 +11,10 @@ class Noosfero::Plugin | ||
11 | @identifier ||= (if self.parents.first.instance_of? Module then self.parents.first else self end).name.underscore | 11 | @identifier ||= (if self.parents.first.instance_of? Module then self.parents.first else self end).name.underscore |
12 | end | 12 | end |
13 | 13 | ||
14 | + def module_name | ||
15 | + @name ||= (if self.parents.first != Object then self.parents.first else self end).to_s | ||
16 | + end | ||
17 | + | ||
14 | def public_name | 18 | def public_name |
15 | @public_name ||= self.identifier.gsub '_plugin', '' | 19 | @public_name ||= self.identifier.gsub '_plugin', '' |
16 | end | 20 | end |