Class: Quby::Questionnaires::Repos::MemoryRepo

Inherits:
Base
  • Object
show all
Defined in:
lib/quby/questionnaires/repos/memory_repo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#all, #create!, #update!

Constructor Details

#initialize(definitions = {}) ⇒ MemoryRepo

Returns a new instance of MemoryRepo.



12
13
14
15
16
# File 'lib/quby/questionnaires/repos/memory_repo.rb', line 12

def initialize(definitions = {})
  @records = definitions.map do |key, definition|
    [key, record_for_definition(definition)]
  end.to_h
end

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



10
11
12
# File 'lib/quby/questionnaires/repos/memory_repo.rb', line 10

def records
  @records
end

Instance Method Details

#exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/quby/questionnaires/repos/memory_repo.rb', line 28

def exists?(key)
  records.key?(key)
end

#find(key) ⇒ Object



22
23
24
25
26
# File 'lib/quby/questionnaires/repos/memory_repo.rb', line 22

def find(key)
  fail(QuestionnaireNotFound, key) unless exists?(key)
  record = records.fetch(key)
  entity(key, record.fetch(:definition), record.fetch(:last_update), "memoryrepo #{key}")
end

#keysObject



18
19
20
# File 'lib/quby/questionnaires/repos/memory_repo.rb', line 18

def keys
  records.keys
end

#timestamp(key) ⇒ Object



32
33
34
35
# File 'lib/quby/questionnaires/repos/memory_repo.rb', line 32

def timestamp(key)
  fail(QuestionnaireNotFound, key) unless exists?(key)
  records.fetch(key).fetch(:last_update)
end