Class: Plugins

Inherits:
Object
  • Object
show all
Defined in:
lib/plugins.rb,
lib/plugins/errors.rb,
lib/plugins/plugin.rb,
lib/plugins/version.rb,
lib/plugins/block_stack.rb,
lib/plugins/around_stack.rb,
lib/plugins/component_mixin.rb

Defined Under Namespace

Modules: ComponentMixin, Errors Classes: AroundStack, BlockStack, Plugin

Constant Summary collapse

VERSION =
"0.3.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component = nil, &block) ⇒ Plugins

Returns a new instance of Plugins.



12
13
14
15
# File 'lib/plugins.rb', line 12

def initialize(component=nil, &block)
  @component = component
  @plugin_loader = block
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



10
11
12
# File 'lib/plugins.rb', line 10

def component
  @component
end

#plugin_loaderObject (readonly)

Returns the value of attribute plugin_loader.



10
11
12
# File 'lib/plugins.rb', line 10

def plugin_loader
  @plugin_loader
end

Instance Method Details

#add(plugin = nil, *args, &block) ⇒ Object



17
18
19
20
# File 'lib/plugins.rb', line 17

def add(plugin=nil, *args, &block)
  plugin = _load(plugin, &block)
  _add_plugin(plugin.new(self, *args))
end

#after(subject, *args) ⇒ Object



31
32
33
# File 'lib/plugins.rb', line 31

def after(subject, *args)
  _plugins.reverse_each { |plugin| plugin.after(subject, *args) }
end

#around(subject, *args, &block) ⇒ Object



35
36
37
# File 'lib/plugins.rb', line 35

def around(subject, *args, &block)
  _around_stack.call(subject, *args) { |subject, *args| block.call(*args) }
end

#before(subject, *args) ⇒ Object



27
28
29
# File 'lib/plugins.rb', line 27

def before(subject, *args)
  _plugins.reverse_each { |plugin| plugin.before(subject, *args) }
end

#clearObject



22
23
24
25
# File 'lib/plugins.rb', line 22

def clear
  @_plugins = nil
  @_around_stack = nil
end

#perform(subject, *args, &block) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/plugins.rb', line 39

def perform(subject, *args, &block)
  before(subject, *args)
  retval = around(subject, *args, &block)
  after(subject, *args)

  retval
end