Class: Faraday::Adapter::Test::Stub
- Inherits:
-
Struct
- Object
- Struct
- 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.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#host ⇒ Object
Returns the value of attribute host.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #headers_match?(request_headers) ⇒ Boolean
-
#initialize(host, full, headers, body, block) ⇒ Stub
constructor
A new instance of Stub.
- #matches?(request_host, request_uri, request_headers, request_body) ⇒ Boolean
- #params_match?(request_params) ⇒ Boolean
- #path_match?(request_path, meta) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(host, full, headers, body, block) ⇒ Stub
Returns a new instance of Stub.
133 134 135 136 137 138 139 |
# File 'lib/faraday/adapter/test.rb', line 133 def initialize(host, full, headers, body, block) path, query = full.respond_to?(:split) ? full.split("?") : full params = query ? Faraday::Utils.parse_nested_query(query) : {} super(host, path, params, headers, body, block) end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block
132 133 134 |
# File 'lib/faraday/adapter/test.rb', line 132 def block @block end |
#body ⇒ Object
Returns the value of attribute body
132 133 134 |
# File 'lib/faraday/adapter/test.rb', line 132 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers
132 133 134 |
# File 'lib/faraday/adapter/test.rb', line 132 def headers @headers end |
#host ⇒ Object
Returns the value of attribute host
132 133 134 |
# File 'lib/faraday/adapter/test.rb', line 132 def host @host end |
#params ⇒ Object
Returns the value of attribute params
132 133 134 |
# File 'lib/faraday/adapter/test.rb', line 132 def params @params end |
#path ⇒ Object
Returns the value of attribute path
132 133 134 |
# File 'lib/faraday/adapter/test.rb', line 132 def path @path end |
Instance Method Details
#headers_match?(request_headers) ⇒ Boolean
170 171 172 173 174 |
# File 'lib/faraday/adapter/test.rb', line 170 def headers_match?(request_headers) headers.keys.all? do |key| request_headers[key] == headers[key] end end |
#matches?(request_host, request_uri, request_headers, request_body) ⇒ Boolean
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/faraday/adapter/test.rb', line 141 def matches?(request_host, request_uri, request_headers, request_body) request_path, request_query = request_uri.split('?') request_params = request_query ? Faraday::Utils.parse_nested_query(request_query) : {} # meta is a hash use as carrier # that will be yielded to consumer block = {} return (host.nil? || host == request_host) && path_match?(request_path, ) && params_match?(request_params) && (body.to_s.size.zero? || request_body == body) && headers_match?(request_headers), end |
#params_match?(request_params) ⇒ Boolean
164 165 166 167 168 |
# File 'lib/faraday/adapter/test.rb', line 164 def params_match?(request_params) params.keys.all? do |key| request_params[key] == params[key] end end |
#path_match?(request_path, meta) ⇒ Boolean
156 157 158 159 160 161 162 |
# File 'lib/faraday/adapter/test.rb', line 156 def path_match?(request_path, ) if path.is_a? Regexp !!([:match_data] = path.match(request_path)) else path == request_path end end |
#to_s ⇒ Object
176 177 178 |
# File 'lib/faraday/adapter/test.rb', line 176 def to_s "#{path} #{body}" end |