Class: Fake::RequestHandler
- Inherits:
-
Object
- Object
- Fake::RequestHandler
- Defined in:
- lib/fake/request_handler.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#responses ⇒ Object
readonly
Returns the value of attribute responses.
Instance Method Summary collapse
- #call(request) ⇒ Object
-
#initialize(method, path) ⇒ RequestHandler
constructor
Creates handler for http request method: :get, :post, :put etc path: Path of the request like ‘/home/something’.
Constructor Details
#initialize(method, path) ⇒ RequestHandler
Creates handler for http request method: :get, :post, :put etc path: Path of the request like ‘/home/something’
13 14 15 16 17 18 19 20 |
# File 'lib/fake/request_handler.rb', line 13 def initialize(method, path) @method = method uri = URI.parse(path) @params = parse_params(uri) @path = Path.new(uri.path) @responses = InfiniteQueue.new @body = nil end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
7 8 9 |
# File 'lib/fake/request_handler.rb', line 7 def body @body end |
#responses ⇒ Object (readonly)
Returns the value of attribute responses.
6 7 8 |
# File 'lib/fake/request_handler.rb', line 6 def responses @responses end |
Instance Method Details
#call(request) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/fake/request_handler.rb', line 22 def call(request) if should_serve?(request) current_response = @responses.next raise "FAKE service: No response set for request #{presentation}" if current_response.nil? current_response.evaluate() Rack::Response.new([current_response.body], status=current_response.status, header=current_response.headers) end end |