Module: Pact::DSL

Defined in:
lib/pact/shared/dsl.rb

Overview

Ripped from blog.joecorcoran.co.uk/2013/09/04/simple-pattern-ruby-dsl and then fixed up by using www.skorks.com/2013/03/a-closure-is-not-always-a-closure-in-ruby/ to access variables and methods defined in the calling scope.

Instance Method Summary collapse

Instance Method Details

#build(*args, &block) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/pact/shared/dsl.rb', line 61

def build(*args, &block)
  new_instance_of_delegation_target_class = self.new(*args)
  dsl_delegator_class = self.const_get('DSL_DELEGATOR_CLASS')
  dsl_delegator = dsl_delegator_class.new(new_instance_of_delegation_target_class)
  dsl_delegator.instance_eval_with_previous_context_available(&block) if block
  new_instance_of_delegation_target_class.finalize
  new_instance_of_delegation_target_class
end

#dsl(&block) ⇒ Object



70
71
72
73
# File 'lib/pact/shared/dsl.rb', line 70

def dsl(&block)
  dsl_delegator_class = Class.new(DslDelegator, &block)
  self.const_set('DSL_DELEGATOR_CLASS', dsl_delegator_class)
end