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_result_registry) ⇒ Controller
constructor
A new instance of Controller.
- #match(request, logger) ⇒ Object
- #register(request, logger) ⇒ Object
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 |