class Pact::DslDelegator

Attributes

delegation_target[RW]
previous_context[RW]

Public Class Methods

new(delegation_target) click to toggle source
# File lib/pact/shared/dsl.rb, line 5
def initialize delegation_target
  @delegation_target = delegation_target
end

Public Instance Methods

instance_eval_with_previous_context_available(*args, &block) click to toggle source
# File lib/pact/shared/dsl.rb, line 9
def instance_eval_with_previous_context_available(*args, &block)
  with_previous_context_available(block.binding) do
    bind_block_as_instance_method_on_self(&block).call(*args)
  end
end

Protected Instance Methods

method_missing(method, *args, &block) click to toggle source
# File lib/pact/shared/dsl.rb, line 17
def method_missing(method, *args, &block)
  if delegation_target_responds_to? method
    delegation_target.send(method, *args, &block)
  else
    previous_context.send(method, *args, &block)
  end
end

Private Instance Methods

bind_block_as_instance_method_on_self(&block) click to toggle source
# File lib/pact/shared/dsl.rb, line 29
def bind_block_as_instance_method_on_self(&block)
  create_instance_method_from_block(&block).bind(self)
end
create_instance_method_from_block(&block) click to toggle source
# File lib/pact/shared/dsl.rb, line 34
def create_instance_method_from_block &block
  meth = self.class.class_eval do
    define_method :block_as_instance_method_, &block
    meth = instance_method :block_as_instance_method_
    remove_method :block_as_instance_method_
    meth
  end
end
delegation_target_responds_to?(method) click to toggle source
# File lib/pact/shared/dsl.rb, line 50
def delegation_target_responds_to?(method)
  delegation_target.respond_to? method
end
with_previous_context_available(binding, &block) click to toggle source
# File lib/pact/shared/dsl.rb, line 43
def with_previous_context_available(binding, &block)
  @previous_context = binding.eval('self')
  result = block.call
  @previous_context = nil
  result
end