Class: HttpStub::Server::Stub::Controller
- Inherits:
-
Object
- Object
- HttpStub::Server::Stub::Controller
- Defined in:
- lib/http_stub/server/stub/controller.rb
Instance Method Summary collapse
- #clear(logger) ⇒ Object
-
#initialize(stub_registry, match_registry, miss_registry) ⇒ Controller
constructor
A new instance of Controller.
- #match(request, logger) ⇒ Object
- #register(request, logger) ⇒ Object
Constructor Details
#initialize(stub_registry, match_registry, miss_registry) ⇒ Controller
Returns a new instance of Controller.
7 8 9 10 11 |
# File 'lib/http_stub/server/stub/controller.rb', line 7 def initialize(stub_registry, match_registry, miss_registry) @stub_registry = stub_registry @match_registry = match_registry @miss_registry = miss_registry end |
Instance Method Details
#clear(logger) ⇒ Object
27 28 29 |
# File 'lib/http_stub/server/stub/controller.rb', line 27 def clear(logger) [ @stub_registry, @match_registry, @miss_registry ].each { |registry| registry.clear(logger) } end |
#match(request, logger) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/http_stub/server/stub/controller.rb', line 19 def match(request, logger) stub = @stub_registry.match(request, logger) response = stub ? stub.response_for(request) : HttpStub::Server::Response::NOT_FOUND @match_registry.add(HttpStub::Server::Stub::Match::Match.new(request, response, stub), logger) if stub @miss_registry.add(HttpStub::Server::Stub::Match::Miss.new(request), logger) unless stub response end |
#register(request, logger) ⇒ Object
13 14 15 16 17 |
# File 'lib/http_stub/server/stub/controller.rb', line 13 def register(request, logger) stub = HttpStub::Server::Stub.create(HttpStub::Server::Stub::Parser.parse(request)) @stub_registry.add(stub, logger) HttpStub::Server::Response.ok("headers" => { "location" => stub.uri }) end |