Class: HttpStub::Server::Stub::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/http_stub/server/stub/controller.rb

Instance Method Summary collapse

Constructor Details

#initialize(stub_registry, match_result_registry) ⇒ Controller

Returns a new instance of Controller.



7
8
9
10
# File 'lib/http_stub/server/stub/controller.rb', line 7

def initialize(stub_registry, match_result_registry)
  @stub_registry         = stub_registry
  @match_result_registry = match_result_registry
end

Instance Method Details

#clear(logger) ⇒ Object



25
26
27
# File 'lib/http_stub/server/stub/controller.rb', line 25

def clear(logger)
  [ @stub_registry, @match_result_registry ].each { |registry| registry.clear(logger) }
end

#match(request, logger) ⇒ Object



18
19
20
21
22
23
# File 'lib/http_stub/server/stub/controller.rb', line 18

def match(request, logger)
  stub = @stub_registry.match(request, logger)
  response = stub ? stub.response_for(request) : HttpStub::Server::Response::NOT_FOUND
  @match_result_registry.add(HttpStub::Server::Stub::Match::Result.new(request, response, stub), logger)
  response
end

#register(request, logger) ⇒ Object



12
13
14
15
16
# File 'lib/http_stub/server/stub/controller.rb', line 12

def register(request, logger)
  stub = HttpStub::Server::Stub.create(HttpStub::Server::Stub::Parser.parse(request))
  @stub_registry.add(stub, logger)
  HttpStub::Server::Response.success("location" => stub.stub_uri)
end