Class: Contracto::Contract

Inherits:
Object
  • Object
show all
Defined in:
lib/contracto/contract.rb

Defined Under Namespace

Classes: Request, Response, Responses

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Contract

Returns a new instance of Contract.



8
9
10
11
12
# File 'lib/contracto/contract.rb', line 8

def initialize(hash)
  @hash = hash
  @request   = Contracto::Contract::Request.new(@hash.fetch('schema').fetch('request'))
  @responses = Contracto::Contract::Responses.new(@hash.fetch('examples'))
end

Instance Attribute Details

#responsesObject (readonly)

Returns the value of attribute responses.



6
7
8
# File 'lib/contracto/contract.rb', line 6

def responses
  @responses
end

Instance Method Details

#http_methodObject



14
15
16
# File 'lib/contracto/contract.rb', line 14

def http_method
  @request.http_method
end

#response_body(params, headers) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/contracto/contract.rb', line 22

def response_body(params, headers)
  response = @responses.find_by_params_and_headers(params, headers)
  raise Contracto::ResponseNotFoundError.new(params) unless response
  response.body.tap do
    Contracto::Stats.used_contracts << self unless Contracto::Stats.used_contracts.include?(self)
  end
end

#url_patternObject



18
19
20
# File 'lib/contracto/contract.rb', line 18

def url_pattern
  @request.url_pattern
end