Class: HttpStub::Controllers::StubActivatorController

Inherits:
Object
  • Object
show all
Defined in:
lib/http_stub/controllers/stub_activator_controller.rb

Instance Method Summary collapse

Constructor Details

#initialize(stub_activator_registry, stub_registry) ⇒ StubActivatorController

Returns a new instance of StubActivatorController.



6
7
8
9
# File 'lib/http_stub/controllers/stub_activator_controller.rb', line 6

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

Instance Method Details

#activate(request) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/http_stub/controllers/stub_activator_controller.rb', line 16

def activate(request)
  activator = @stub_activator_registry.find_for(request)
  if activator
    @stub_registry.add(activator.the_stub, request)
    HttpStub::Models::Response::SUCCESS
  else
    HttpStub::Models::Response::EMPTY
  end
end

#clear(request) ⇒ Object



26
27
28
# File 'lib/http_stub/controllers/stub_activator_controller.rb', line 26

def clear(request)
  @stub_activator_registry.clear(request)
end

#register(request) ⇒ Object



11
12
13
14
# File 'lib/http_stub/controllers/stub_activator_controller.rb', line 11

def register(request)
  @stub_activator_registry.add(HttpStub::Models::StubActivator.new(JSON.parse(request.body.read)), request)
  HttpStub::Models::Response::SUCCESS
end