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_INDICATOR
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
- #as_json(options = {}) ⇒ Object
- #full_path ⇒ Object
-
#initialize(method, path, headers, body, query) ⇒ Base
constructor
A new instance of Base.
- #method_and_path ⇒ Object
- #to_hash ⇒ Object
- #to_json(options = {}) ⇒ Object
Methods included from Matchers
actual_array_diff, actual_hash_diff, array_diff, check_for_unexpected_keys, class_diff, classes_match?, diff, hash_diff, object_diff, regexp_diff, structure_diff, structure_diff_actual_display, structure_diff_expected_display
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.chomp('/') @headers = headers @body = body @query = 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
#as_json(options = {}) ⇒ Object
27 28 29 |
# File 'lib/pact/shared/request.rb', line 27 def as_json = {} to_hash end |
#full_path ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pact/shared/request.rb', line 47 def full_path fp = '' if path.empty? fp << "/" else fp << path end if query && !query.empty? fp << ("?" + (query.kind_of?(Pact::Term) ? query.generate : query)) end fp end |
#method_and_path ⇒ Object
43 44 45 |
# File 'lib/pact/shared/request.rb', line 43 def method_and_path "#{method.upcase} #{path}" end |
#to_hash ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pact/shared/request.rb', line 31 def to_hash base_json = { method: method, path: path, } base_json.merge!(body: body) unless body.is_a? self.class.key_not_found.class base_json.merge!(headers: headers) unless headers.is_a? self.class.key_not_found.class base_json.merge!(query: query) unless query.is_a? self.class.key_not_found.class base_json end |
#to_json(options = {}) ⇒ Object
23 24 25 |
# File 'lib/pact/shared/request.rb', line 23 def to_json( = {}) as_json.to_json() end |