Class: HttpStub::Server::Registry

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

Instance Method Summary collapse

Constructor Details

#initialize(model_name, models = []) ⇒ Registry

Returns a new instance of Registry.


8
9
10
11
# File 'lib/http_stub/server/registry.rb', line 8

def initialize(model_name, models=[])
  @model_name = model_name
  @models     = models.reverse
end

Instance Method Details

#add(model, logger) ⇒ Object


13
14
15
16
# File 'lib/http_stub/server/registry.rb', line 13

def add(model, logger)
  @models.unshift(model)
  log_addition_of([ model ], logger)
end

#allObject


38
39
40
# File 'lib/http_stub/server/registry.rb', line 38

def all
  Array.new(@models)
end

#clear(logger) ⇒ Object


47
48
49
50
# File 'lib/http_stub/server/registry.rb', line 47

def clear(logger)
  log_pending_clear(logger)
  @models.clear
end

#concat(models, logger) ⇒ Object


18
19
20
21
# File 'lib/http_stub/server/registry.rb', line 18

def concat(models, logger)
  @models.unshift(*models.reverse)
  log_addition_of(models.reverse, logger)
end

#delete(criteria, logger) ⇒ Object


42
43
44
45
# File 'lib/http_stub/server/registry.rb', line 42

def delete(criteria, logger)
  logger.info "Deleting #{@model_name} matching: #{criteria}"
  @models.delete_if { |model| model.matches?(criteria, logger) }
end

#find(criteria, logger) ⇒ Object


29
30
31
32
# File 'lib/http_stub/server/registry.rb', line 29

def find(criteria, logger)
  logger.info "Finding #{@model_name} matching: #{criteria}"
  @models.find { |model| model.matches?(criteria, logger) }
end

#lastObject


34
35
36
# File 'lib/http_stub/server/registry.rb', line 34

def last
  @models.first
end

#replace(models, logger) ⇒ Object


23
24
25
26
27
# File 'lib/http_stub/server/registry.rb', line 23

def replace(models, logger)
  log_pending_clear(logger)
  @models.replace(models.reverse)
  log_addition_of(models.reverse, logger)
end