Class: FakeHTTP::Responder
- Inherits:
-
Object
- Object
- FakeHTTP::Responder
- Defined in:
- lib/fake_http.rb
Instance Method Summary collapse
- #call(uri, options) ⇒ Object
- #content_type(mime_type) ⇒ Object
- #headers ⇒ Object
-
#initialize(pattern, code) ⇒ Responder
constructor
A new instance of Responder.
- #match(uri) ⇒ Object
- #status(new_status = nil) ⇒ Object
Constructor Details
#initialize(pattern, code) ⇒ Responder
Returns a new instance of Responder.
75 76 77 |
# File 'lib/fake_http.rb', line 75 def initialize(pattern, code) @pattern, @code = Mustermann.new(pattern), code end |
Instance Method Details
#call(uri, options) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/fake_http.rb', line 83 def call(uri, ) params = @pattern.params(uri) status 200 content_type "application/json" body = instance_exec(params, , &@code) HTTP::Response.new(status: status, version: "1.1", headers: headers, body: body.to_json) end |
#content_type(mime_type) ⇒ Object
96 97 98 |
# File 'lib/fake_http.rb', line 96 def content_type(mime_type) headers["Content-Type"] = mime_type end |
#headers ⇒ Object
100 101 102 |
# File 'lib/fake_http.rb', line 100 def headers @headers ||= {} end |
#match(uri) ⇒ Object
79 80 81 |
# File 'lib/fake_http.rb', line 79 def match(uri) @pattern.match(uri) end |
#status(new_status = nil) ⇒ Object
91 92 93 94 |
# File 'lib/fake_http.rb', line 91 def status(new_status=nil) @status = new_status if new_status @status end |