Class: Pact::Request::Base
- Inherits:
-
Object
- Object
- Pact::Request::Base
- Extended by:
- Matchers
- Includes:
- Matchers, SymbolizeKeys
- Defined in:
- lib/pact/shared/request.rb
Direct Known Subclasses
Constant Summary
Constants included from Matchers
Matchers::DEFAULT_OPTIONS, Matchers::NO_DIFF, Matchers::NO_DIFF_AT_INDEX
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
- #content_type ⇒ Object
- #content_type?(content_type) ⇒ Boolean
- #full_path ⇒ Object
-
#initialize(method, path, headers, body, query) ⇒ Base
constructor
A new instance of Base.
- #method_and_path ⇒ Object
- #modifies_resource? ⇒ Boolean
- #specified?(key) ⇒ Boolean
- #to_hash ⇒ Object
Methods included from Matchers
Methods included from SymbolizeKeys
Constructor Details
#initialize(method, path, headers, body, query) ⇒ Base
Returns a new instance of Base.
17 18 19 20 21 22 23 |
# File 'lib/pact/shared/request.rb', line 17 def initialize(method, path, headers, body, query) @method = method.to_s @path = path.respond_to?(:chomp) ? path.chomp('/') : path #TODO get rid of the chomp in v2 @headers = Hash === headers ? Headers.new(headers) : headers # Could be a NullExpectation - TODO make this more elegant @body = body @query = is_unspecified?(query) ? query : Pact::Query.create(query) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
15 16 17 |
# File 'lib/pact/shared/request.rb', line 15 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
15 16 17 |
# File 'lib/pact/shared/request.rb', line 15 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
15 16 17 |
# File 'lib/pact/shared/request.rb', line 15 def method @method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/pact/shared/request.rb', line 15 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
15 16 17 |
# File 'lib/pact/shared/request.rb', line 15 def path @path end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
15 16 17 |
# File 'lib/pact/shared/request.rb', line 15 def query @query end |
Instance Method Details
#content_type ⇒ Object
44 45 46 47 |
# File 'lib/pact/shared/request.rb', line 44 def content_type return nil unless specified?(:headers) headers['Content-Type'] end |
#content_type?(content_type) ⇒ Boolean
49 50 51 |
# File 'lib/pact/shared/request.rb', line 49 def content_type? content_type self.content_type == content_type end |
#full_path ⇒ Object
40 41 42 |
# File 'lib/pact/shared/request.rb', line 40 def full_path display_path + display_query end |
#method_and_path ⇒ Object
36 37 38 |
# File 'lib/pact/shared/request.rb', line 36 def method_and_path "#{method.upcase} #{full_path}" end |
#modifies_resource? ⇒ Boolean
53 54 55 |
# File 'lib/pact/shared/request.rb', line 53 def modifies_resource? http_method_modifies_resource? && body_specified? end |
#specified?(key) ⇒ Boolean
57 58 59 |
# File 'lib/pact/shared/request.rb', line 57 def specified? key !is_unspecified?(self.send(key)) end |
#to_hash ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pact/shared/request.rb', line 25 def to_hash hash = { method: method, path: path, } hash[:query] = query if specified?(:query) hash[:headers] = headers if specified?(:headers) hash[:body] = body if specified?(:body) hash end |