Module: Vedeu::Store
Overview
Provides generic repository related behaviour.
Instance Method Summary collapse
- #each(&block) ⇒ Enumerator
-
#empty? ⇒ Boolean
Return a boolean indicating whether the storage is empty.
-
#exists?(name) ⇒ Boolean
(also: #registered?)
Returns a boolean indicating whether the named model is registered.
- #in_memory ⇒ Hash
-
#registered ⇒ Array
Returns a collection of the names of all the registered entities.
-
#reset ⇒ Array|Hash|Set
(also: #reset!, #clear)
Remove all currently stored data.
-
#size ⇒ Fixnum
Return the number of entries stored.
-
#storage ⇒ Array|Hash|Set
(also: #all)
Return whole repository; provides raw access to the storage for this repository.
Instance Method Details
#each(&block) ⇒ Enumerator
11 12 13 |
# File 'lib/vedeu/repositories/store.rb', line 11 def each(&block) storage.each(&block) end |
#empty? ⇒ Boolean
Return a boolean indicating whether the storage is empty.
18 19 20 |
# File 'lib/vedeu/repositories/store.rb', line 18 def empty? storage.empty? end |
#exists?(name) ⇒ Boolean Also known as: registered?
Returns a boolean indicating whether the named model is registered.
27 28 29 30 31 |
# File 'lib/vedeu/repositories/store.rb', line 27 def exists?(name) return false if empty? || name.nil? || name.empty? storage.include?(name) end |
#in_memory ⇒ Hash
75 76 77 |
# File 'lib/vedeu/repositories/store.rb', line 75 def in_memory {} end |
#registered ⇒ Array
Returns a collection of the names of all the registered entities.
38 39 40 41 42 43 44 |
# File 'lib/vedeu/repositories/store.rb', line 38 def registered return [] if empty? return storage.keys if storage.is_a?(Hash) return storage.to_a if storage.is_a?(Set) storage end |
#reset ⇒ Array|Hash|Set Also known as: reset!, clear
Remove all currently stored data.
49 50 51 52 53 54 |
# File 'lib/vedeu/repositories/store.rb', line 49 def reset Vedeu.log(type: :reset, message: "(#{self.class.name}) #{registered.inspect}") @storage = in_memory end |
#size ⇒ Fixnum
Return the number of entries stored.
61 62 63 |
# File 'lib/vedeu/repositories/store.rb', line 61 def size storage.size end |
#storage ⇒ Array|Hash|Set Also known as: all
Return whole repository; provides raw access to the storage for this repository.
69 70 71 |
# File 'lib/vedeu/repositories/store.rb', line 69 def storage @storage ||= in_memory end |