Class: Fake::RequestHandler

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bodyObject

Returns the value of attribute body.



7
8
9
# File 'lib/fake/request_handler.rb', line 7

def body
  @body
end

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