Class: Quby::Questionnaires::Repos::MemoryRepo
- Defined in:
- lib/quby/questionnaires/repos/memory_repo.rb
Instance Attribute Summary collapse
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Instance Method Summary collapse
- #exists?(key) ⇒ Boolean
- #find(key) ⇒ Object
-
#initialize(definitions = {}) ⇒ MemoryRepo
constructor
A new instance of MemoryRepo.
- #keys ⇒ Object
- #timestamp(key) ⇒ Object
Methods inherited from Base
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
#records ⇒ Object (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
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 |
#keys ⇒ Object
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 (key) fail(QuestionnaireNotFound, key) unless exists?(key) records.fetch(key).fetch(:last_update) end |