Class: HTTP::Fake::Responder
- Inherits:
-
Object
- Object
- HTTP::Fake::Responder
- Defined in:
- lib/http/fake/responder.rb
Overview
Handles an outgoing response.
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
- #call(path, arguments = {}) ⇒ Object
-
#initialize(verb, pattern, function) ⇒ Responder
constructor
A new instance of Responder.
- #match?(verb, path) ⇒ Boolean
- #status(code = nil) ⇒ Object
Constructor Details
#initialize(verb, pattern, function) ⇒ Responder
Returns a new instance of Responder.
14 15 16 17 18 19 |
# File 'lib/http/fake/responder.rb', line 14 def initialize verb, pattern, function @verb = verb @pattern = Mustermann.new pattern @function = function @headers = {} end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
12 13 14 |
# File 'lib/http/fake/responder.rb', line 12 def headers @headers end |
Instance Method Details
#call(path, arguments = {}) ⇒ Object
23 24 25 26 27 |
# File 'lib/http/fake/responder.rb', line 23 def call path, arguments = {} pattern.params(path) .then { |params| instance_exec(params, arguments, &function) } .then { |data| connect path, data } end |
#match?(verb, path) ⇒ Boolean
21 |
# File 'lib/http/fake/responder.rb', line 21 def match?(verb, path) = !String(pattern.match(path)).blank? && verb == self.verb |
#status(code = nil) ⇒ Object
29 |
# File 'lib/http/fake/responder.rb', line 29 def status(code = nil) = @status ||= code |