Class: Faraday::Adapter::Test::Stub
- Defined in:
- lib/faraday/adapter/test.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#body ⇒ Object
Returns the value of attribute body.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(full, body, block) ⇒ Stub
constructor
A new instance of Stub.
- #matches?(request_uri, request_body) ⇒ Boolean
- #params_match?(request_params) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(full, body, block) ⇒ Stub
Returns a new instance of Stub.
106 107 108 109 110 111 112 |
# File 'lib/faraday/adapter/test.rb', line 106 def initialize(full, body, block) path, query = full.split('?') params = query ? Faraday::Utils.parse_nested_query(query) : {} super path, params, body, block end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block
105 106 107 |
# File 'lib/faraday/adapter/test.rb', line 105 def block @block end |
#body ⇒ Object
Returns the value of attribute body
105 106 107 |
# File 'lib/faraday/adapter/test.rb', line 105 def body @body end |
#params ⇒ Object
Returns the value of attribute params
105 106 107 |
# File 'lib/faraday/adapter/test.rb', line 105 def params @params end |
#path ⇒ Object
Returns the value of attribute path
105 106 107 |
# File 'lib/faraday/adapter/test.rb', line 105 def path @path end |
Instance Method Details
#matches?(request_uri, request_body) ⇒ Boolean
114 115 116 117 118 119 120 121 122 |
# File 'lib/faraday/adapter/test.rb', line 114 def matches?(request_uri, request_body) request_path, request_query = request_uri.split('?') request_params = request_query ? Faraday::Utils.parse_nested_query(request_query) : {} request_path == path && params_match?(request_params) && (body.to_s.size.zero? || request_body == body) end |
#params_match?(request_params) ⇒ Boolean
124 125 126 127 128 |
# File 'lib/faraday/adapter/test.rb', line 124 def params_match?(request_params) params.keys.all? do |key| request_params[key] == params[key] end end |
#to_s ⇒ Object
130 131 132 |
# File 'lib/faraday/adapter/test.rb', line 130 def to_s "#{path} #{body}" end |