Commit 2572302ae85ec0d4aee7e663a03b8b6844f10ee6

Authored by Braulio Bhavamitra
1 parent 6b50d1d9

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
lib/noosfero/plugin.rb
... ... @@ -138,11 +138,12 @@ class Noosfero::Plugin
138 138 filters = [filters]
139 139 end
140 140 filters.each do |plugin_filter|
  141 + plugin_filter[:options] ||= {}
  142 + plugin_filter[:options][:if] = -> { environment.plugin_enabled? plugin.module_name }
  143 +
141 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 147 end
147 148 end
148 149  
... ...
lib/noosfero/plugin/parent_methods.rb
... ... @@ -11,6 +11,10 @@ class Noosfero::Plugin
11 11 @identifier ||= (if self.parents.first.instance_of? Module then self.parents.first else self end).name.underscore
12 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 18 def public_name
15 19 @public_name ||= self.identifier.gsub '_plugin', ''
16 20 end
... ...