Class: HTTP::Fake::Responder

Inherits:
Object
  • Object
show all
Defined in:
lib/http/fake/responder.rb

Overview

Handles an outgoing response.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#headersObject (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

Returns:

  • (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