Class: Ribbon::Plugins

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

Defined Under Namespace

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

Constant Summary collapse

VERSION =
"0.2.4"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Plugins


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

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

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component


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

def component
  @component
end

#plugin_loaderObject (readonly)

Returns the value of attribute plugin_loader


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

def plugin_loader
  @plugin_loader
end

Instance Method Details

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


18
19
20
21
# 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) ⇒ Object


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

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

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


36
37
38
# 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) ⇒ Object


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

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

#clearObject


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

def clear
  @_plugins = nil
  @_around_stack = nil
end

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


40
41
42
43
44
45
46
# 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