Class: HttpStub::Server::Scenario::Controller

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

Instance Method Summary collapse

Constructor Details

#initialize(server_memory) ⇒ Controller

Returns a new instance of Controller.


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

def initialize(server_memory)
  @scenario_registry = server_memory.scenario_registry
end

Instance Method Details

#activate(request, logger) ⇒ Object


19
20
21
22
23
24
25
# File 'lib/http_stub/server/scenario/controller.rb', line 19

def activate(request, logger)
  scenario_names = request.parameters[:name] ? [request.parameters[:name] ] : request.parameters[:names]
  scenario_names.each { |name| request.session.activate_scenario!(name, logger) }
  HttpStub::Server::Response::OK
rescue HttpStub::Server::Scenario::NotFoundError => error
  HttpStub::Server::Response.invalid_request(error)
end

#find(request, logger) ⇒ Object


11
12
13
# File 'lib/http_stub/server/scenario/controller.rb', line 11

def find(request, logger)
  @scenario_registry.find(URI.decode_www_form_component(request.parameters[:name]), logger)
end

#find_allObject


15
16
17
# File 'lib/http_stub/server/scenario/controller.rb', line 15

def find_all
  @scenario_registry.all.sort_by(&:name)
end