Class: Contracto::Contract
- Inherits:
-
Object
- Object
- Contracto::Contract
- Defined in:
- lib/contracto/contract.rb
Defined Under Namespace
Classes: Request, Response, Responses
Instance Attribute Summary collapse
-
#responses ⇒ Object
readonly
Returns the value of attribute responses.
Instance Method Summary collapse
- #http_method ⇒ Object
-
#initialize(hash) ⇒ Contract
constructor
A new instance of Contract.
- #response_body(params, headers) ⇒ Object
- #url_pattern ⇒ Object
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
#responses ⇒ Object (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_method ⇒ Object
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_pattern ⇒ Object
18 19 20 |
# File 'lib/contracto/contract.rb', line 18 def url_pattern @request.url_pattern end |