class Ribbon::Plugins
Constants
- VERSION
Attributes
component[R]
plugin_loader[R]
Public Class Methods
new(component=nil, &block)
click to toggle source
# File lib/ribbon/plugins.rb, line 13 def initialize(component=nil, &block) @component = component @plugin_loader = block end
Public Instance Methods
add(plugin=nil, *args, &block)
click to toggle source
# File lib/ribbon/plugins.rb, line 18 def add(plugin=nil, *args, &block) plugin = _load(plugin, &block) _add_plugin(plugin.new(self, *args)) end
after(subject, *args)
click to toggle source
# File lib/ribbon/plugins.rb, line 32 def after(subject, *args) _plugins.reverse_each { |plugin| plugin.after(subject, *args) } end
around(subject, *args, &block)
click to toggle source
# File lib/ribbon/plugins.rb, line 36 def around(subject, *args, &block) _around_stack.call(subject, *args) { |subject, *args| block.call(*args) } end
before(subject, *args)
click to toggle source
# File lib/ribbon/plugins.rb, line 28 def before(subject, *args) _plugins.reverse_each { |plugin| plugin.before(subject, *args) } end
clear()
click to toggle source
# File lib/ribbon/plugins.rb, line 23 def clear @_plugins = nil @_around_stack = nil end
perform(subject, *args, &block)
click to toggle source
# File lib/ribbon/plugins.rb, line 40 def perform(subject, *args, &block) before(subject, *args) retval = around(subject, *args, &block) after(subject, *args) retval end
Private Instance Methods
_add_plugin(plugin)
click to toggle source
# File lib/ribbon/plugins.rb, line 57 def _add_plugin(plugin) _plugins.push(plugin) _around_stack.push { |subject, *args| plugin.around(subject, *args) { |*args| perform_block(subject, *args) } } plugin end
_around_stack()
click to toggle source
# File lib/ribbon/plugins.rb, line 53 def _around_stack @_around_stack ||= AroundStack.new(:block, self) end
_call_plugin_loader(plugin)
click to toggle source
# File lib/ribbon/plugins.rb, line 93 def _call_plugin_loader(plugin) plugin_loader && component.instance_exec(plugin, &plugin_loader) end
_load(plugin, &block)
click to toggle source
# File lib/ribbon/plugins.rb, line 69 def _load(plugin, &block) if plugin _load_plugin(plugin) elsif block_given? Plugin.create(&block) else raise Errors::LoadError, 'No plugin information provided' end end
_load_plugin(plugin)
click to toggle source
# File lib/ribbon/plugins.rb, line 79 def _load_plugin(plugin) _call_plugin_loader(plugin).tap { |p| plugin = p if p } case plugin when Class plugin < Plugin && plugin or raise Errors::LoadError, "Invalid plugin class: #{plugin.inspect} Must extend Plugin." when Proc Plugin.create(&plugin) else raise Errors::LoadError, "Invalid plugin identifier: #{plugin.inspect}" end end
_plugins()
click to toggle source
# File lib/ribbon/plugins.rb, line 49 def _plugins @_plugins ||= [] end