class Ribbon::Plugins::Plugin

Attributes

plugins[R]

Public Class Methods

_callbacks(type, subject) click to toggle source
# File lib/ribbon/plugins/plugin.rb, line 20
def _callbacks(type, subject)
  ((@__callbacks ||= {})[type.to_sym] ||= {})[subject.to_sym] ||= _empty_stack_for(type, subject)
end
_define_callback(type, subject, &block) click to toggle source
# File lib/ribbon/plugins/plugin.rb, line 16
def _define_callback(type, subject, &block)
  _callbacks(type, subject).push(&block)
end
_empty_stack_for(type, subject) click to toggle source
# File lib/ribbon/plugins/plugin.rb, line 24
def _empty_stack_for(type, subject)
  case type.to_sym
  when :before, :after
    BlockStack.new
  when :around
    AroundStack.new(subject)
  else
    raise Errors::Error, "Invalid type: #{type}"
  end
end
create(&block) click to toggle source
# File lib/ribbon/plugins/plugin.rb, line 4
def create(&block)
  Class.new(Plugin).tap { |k| k.class_eval(&block) if block }
end
method_missing(meth, *args, &block) click to toggle source
Calls superclass method
# File lib/ribbon/plugins/plugin.rb, line 8
def method_missing(meth, *args, &block)
  if /^(before|after|around)_(\w+)$/.match(meth.to_s)
    _define_callback($1, $2, &block)
  else
    super
  end
end
new(plugins=nil) click to toggle source
# File lib/ribbon/plugins/plugin.rb, line 38
def initialize(plugins=nil)
  @plugins = plugins
end

Public Instance Methods

after(subject, *args) click to toggle source
# File lib/ribbon/plugins/plugin.rb, line 46
def after(subject, *args)
  _callbacks(:after, subject).call(*args)
end
around(subject, *args, &block) click to toggle source
# File lib/ribbon/plugins/plugin.rb, line 50
def around(subject, *args, &block)
  _callbacks(:around, subject).call(*args, &block)
end
before(subject, *args) click to toggle source
# File lib/ribbon/plugins/plugin.rb, line 42
def before(subject, *args)
  _callbacks(:before, subject).call(*args)
end

Private Instance Methods

_callbacks(type, subject) click to toggle source
# File lib/ribbon/plugins/plugin.rb, line 55
def _callbacks(type, subject)
  ((@_callbacks ||= {})[type.to_sym] ||= {})[subject.to_sym] ||=
    self.class._callbacks(type, subject).dup.tap { |stack|
      stack.scope = self
    }
end