class Compendium::ContextWrapper

Public Class Methods

wrap(ctx, parent, params = nil, &block) click to toggle source
# File lib/compendium/context_wrapper.rb, line 5
def self.wrap(ctx, parent, params = nil, &block)
  delegator = ::SimpleDelegator.new(parent)

  delegator.define_singleton_method(:__context__) { ctx }

  delegator.instance_eval do
    def method_missing(name, *args, &block)
      return __context__.__send__(name, *args, &block) if __context__.respond_to?(name)
      super
    end

    def respond_to_missing?(name, include_private = false)
      return true if __context__.respond_to?(name, include_private)
      super
    end
  end

  return delegator.instance_exec(params, &block) if block_given?

  delegator
end

Public Instance Methods

method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/compendium/context_wrapper.rb, line 11
def method_missing(name, *args, &block)
  return __context__.__send__(name, *args, &block) if __context__.respond_to?(name)
  super
end
respond_to_missing?(name, include_private = false) click to toggle source
Calls superclass method
# File lib/compendium/context_wrapper.rb, line 16
def respond_to_missing?(name, include_private = false)
  return true if __context__.respond_to?(name, include_private)
  super
end