Module: Mondavi::PactRouter::ClassMethods
- Defined in:
- lib/mondavi/pact_router.rb
Instance Method Summary collapse
- #extract_concept(representer, response) ⇒ Object
- #extract_stub(pact_class, concept, method, args) ⇒ Object
- #mock(concept) ⇒ Object
- #pact(method_name, parameter_string, stub) ⇒ Object
- #pact_for(concept) ⇒ Object
Instance Method Details
#extract_concept(representer, response) ⇒ Object
50 51 52 53 54 |
# File 'lib/mondavi/pact_router.rb', line 50 def extract_concept(representer, response) struct = OpenStruct.new struct.extend(representer) struct.from_hash(response) end |
#extract_stub(pact_class, concept, method, args) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/mondavi/pact_router.rb', line 40 def extract_stub(pact_class, concept, method, args) parameter_string = args.to_s if !pacts.has_key?(method) || !pacts[method].has_key?(parameter_string) raise "#{pact_class} does not have #{concept} pact for method ':#{method}' with id key: '#{parameter_string}'" end pacts[method][parameter_string] end |
#mock(concept) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mondavi/pact_router.rb', line 21 def mock(concept) concept.extend(SingleForwardable) # override the methods dynamically defined methods # (defined in RequestRouter using the declarations in the component api) concept.methods(false).each do |method| define_singleton_method(method) do |args| stub = extract_stub(self, concept, method, args) representer = stub.representer response = stub.response return extract_concept(representer, response) end concept.def_delegator self, method, method end end |
#pact(method_name, parameter_string, stub) ⇒ Object
56 57 58 |
# File 'lib/mondavi/pact_router.rb', line 56 def pact method_name, parameter_string, stub pacts[method_name.to_s] = { parameter_string => stub } end |
#pact_for(concept) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/mondavi/pact_router.rb', line 12 def pact_for(concept) is_test = ENV['RACK_ENV'] == 'test' is_external = !IsComponentLocal.call(target_concept: concept) if is_test || is_external mock(concept) end end |