class Ninja::Delegator

Public Class Methods

new(context, opts={}) click to toggle source
# File lib/ninja/delegator.rb, line 3
def initialize(context, opts={})
  @context = context
  # TODO(mtwilliams): Hide standard methods, too.
  @hidden = ((opts[:except] || []).map(&:to_sym))
  @hooks = Hash[((opts.select{|k,_| /^on_.+/.match(k)}).map{|k,v| [k[3..-1].to_sym, v]})]
end

Public Instance Methods

method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/ninja/delegator.rb, line 10
def method_missing(name, *args, &block)
  name = name.to_sym
  super if @hidden.include? name
  if @context.respond_to? name
    response = @context.send(name, *args, &block)
    @hooks[name].call(response) if @hooks.include? name
  else
    super
  end
end