Class: HttpStub::Server::Session::Session

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, scenario_registry, initial_stubs) ⇒ Session

Returns a new instance of Session.


9
10
11
12
13
14
15
# File 'lib/http_stub/server/session/session.rb', line 9

def initialize(id, scenario_registry, initial_stubs)
  @id                  = id
  @scenario_registry   = scenario_registry
  @stub_registry       = HttpStub::Server::Stub::Registry.new(initial_stubs)
  @stub_match_registry = HttpStub::Server::Registry.new("stub match")
  @stub_miss_registry  = HttpStub::Server::Registry.new("stub miss")
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id


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

def id
  @id
end

Instance Method Details

#activate_scenario!(name, logger) ⇒ Object


21
22
23
24
25
26
# File 'lib/http_stub/server/session/session.rb', line 21

def activate_scenario!(name, logger)
  found_scenario = @scenario_registry.find(name, logger)
  raise HttpStub::Server::Scenario::NotFoundError, name unless found_scenario
  activated_stubs = @scenario_registry.stubs_activated_by(found_scenario, logger)
  @stub_registry.concat(activated_stubs, logger)
end

#add_match(match, logger) ⇒ Object


44
45
46
47
48
# File 'lib/http_stub/server/session/session.rb', line 44

def add_match(match, logger)
  @stub_match_registry.add(match, logger)
  match.stub.triggers.scenario_names.each { |scenario_name| activate_scenario!(scenario_name, logger) }
  match.stub.triggers.stubs.each { |stub| add_stub(stub, logger) }
end

#add_miss(miss, logger) ⇒ Object


58
59
60
# File 'lib/http_stub/server/session/session.rb', line 58

def add_miss(miss, logger)
  @stub_miss_registry.add(miss, logger)
end

#add_stub(stub, logger) ⇒ Object


28
29
30
# File 'lib/http_stub/server/session/session.rb', line 28

def add_stub(stub, logger)
  @stub_registry.add(stub, logger)
end

#find_stub(id, logger) ⇒ Object


32
33
34
# File 'lib/http_stub/server/session/session.rb', line 32

def find_stub(id, logger)
  @stub_registry.find(id, logger)
end

#last_match(args, logger) ⇒ Object


54
55
56
# File 'lib/http_stub/server/session/session.rb', line 54

def last_match(args, logger)
  @stub_match_registry.find(args, logger)
end

#match(request, logger) ⇒ Object


40
41
42
# File 'lib/http_stub/server/session/session.rb', line 40

def match(request, logger)
  @stub_registry.match(request, logger)
end

#matchesObject


50
51
52
# File 'lib/http_stub/server/session/session.rb', line 50

def matches
  @stub_match_registry.all
end

#matches?(id, _logger) ⇒ Boolean

Returns:

  • (Boolean)

17
18
19
# File 'lib/http_stub/server/session/session.rb', line 17

def matches?(id, _logger)
  id == @id
end

#missesObject


62
63
64
# File 'lib/http_stub/server/session/session.rb', line 62

def misses
  @stub_miss_registry.all
end

#reset(logger) ⇒ Object


66
67
68
69
70
# File 'lib/http_stub/server/session/session.rb', line 66

def reset(logger)
  @stub_miss_registry.clear(logger)
  @stub_match_registry.clear(logger)
  @stub_registry.reset(logger)
end

#stubsObject


36
37
38
# File 'lib/http_stub/server/session/session.rb', line 36

def stubs
  @stub_registry.all
end