Class: Pact::Request::Base

Inherits:
Object
  • Object
show all
Extended by:
Matchers
Includes:
Matchers, SymbolizeKeys
Defined in:
lib/pact/shared/request.rb

Direct Known Subclasses

Consumer::Request::Actual, Expected

Constant Summary

Constants included from Matchers

Matchers::DEFAULT_OPTIONS, Matchers::NO_DIFF_INDICATOR

Instance Attribute Summary collapse

Instance Method Summary collapse

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

included, #symbolize_keys

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

#bodyObject (readonly)

Returns the value of attribute body.



13
14
15
# File 'lib/pact/shared/request.rb', line 13

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



13
14
15
# File 'lib/pact/shared/request.rb', line 13

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



13
14
15
# File 'lib/pact/shared/request.rb', line 13

def method
  @method
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/pact/shared/request.rb', line 13

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/pact/shared/request.rb', line 13

def path
  @path
end

#queryObject (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 options = {}
  to_hash
end

#full_pathObject



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_pathObject



43
44
45
# File 'lib/pact/shared/request.rb', line 43

def method_and_path
  "#{method.upcase} #{path}"
end

#to_hashObject



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(options = {})
  as_json.to_json(options)
end