Class: Pact::Request::Base
- Inherits:
-
Object
- Object
- Pact::Request::Base
- Includes:
- SymbolizeKeys
- Defined in:
- lib/pact/shared/request.rb
Direct Known Subclasses
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 SymbolizeKeys
Constructor Details
#initialize(method, path, headers, body, query) ⇒ Base
Returns a new instance of Base.
15 16 17 18 19 20 21 |
# File 'lib/pact/shared/request.rb', line 15 def initialize(method, path, headers, body, query) @method = method.to_s @path = path @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.
13 14 15 |
# File 'lib/pact/shared/request.rb', line 13 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
13 14 15 |
# File 'lib/pact/shared/request.rb', line 13 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
13 14 15 |
# File 'lib/pact/shared/request.rb', line 13 def method @method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/pact/shared/request.rb', line 13 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/pact/shared/request.rb', line 13 def path @path end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
13 14 15 |
# File 'lib/pact/shared/request.rb', line 13 def query @query end |
Instance Method Details
#content_type ⇒ Object
42 43 44 45 |
# File 'lib/pact/shared/request.rb', line 42 def content_type return nil unless specified?(:headers) && headers['Content-Type'] Pact::Reification.from_term(headers['Content-Type']) end |
#content_type?(content_type) ⇒ Boolean
47 48 49 |
# File 'lib/pact/shared/request.rb', line 47 def content_type? content_type self.content_type == content_type end |
#full_path ⇒ Object
38 39 40 |
# File 'lib/pact/shared/request.rb', line 38 def full_path display_path + display_query end |
#method_and_path ⇒ Object
34 35 36 |
# File 'lib/pact/shared/request.rb', line 34 def method_and_path "#{method.upcase} #{full_path}" end |
#modifies_resource? ⇒ Boolean
51 52 53 |
# File 'lib/pact/shared/request.rb', line 51 def modifies_resource? http_method_modifies_resource? && body_specified? end |
#specified?(key) ⇒ Boolean
55 56 57 |
# File 'lib/pact/shared/request.rb', line 55 def specified? key !is_unspecified?(self.send(key)) end |
#to_hash ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pact/shared/request.rb', line 23 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 |