Module: Vedeu::Repositories::Store
Overview
Provides generic repository related behaviour.
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable is nil or empty.
-
#demodulize(klass) ⇒ String
included
from Common
Removes the module part from the expression in the string.
- #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
-
#present?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable has a useful value.
-
#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.
-
#snake_case(name) ⇒ String
included
from Common
Converts a class name to a lowercase snake case string.
-
#storage ⇒ Array|Hash|Set
(also: #all)
Return whole repository; provides raw access to the storage for this repository.
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable is nil or empty.
#demodulize(klass) ⇒ String Originally defined in module Common
Removes the module part from the expression in the string.
#each(&block) ⇒ Enumerator
14 15 16 |
# File 'lib/vedeu/repositories/store.rb', line 14 def each(&block) storage.each(&block) end |
#empty? ⇒ Boolean
Return a boolean indicating whether the storage is empty.
21 22 23 |
# File 'lib/vedeu/repositories/store.rb', line 21 def empty? storage.empty? end |
#exists?(name) ⇒ Boolean Also known as: registered?
Returns a boolean indicating whether the named model is registered.
30 31 32 33 34 |
# File 'lib/vedeu/repositories/store.rb', line 30 def exists?(name) return false if empty? || absent?(name) storage.include?(name) end |
#in_memory ⇒ Hash
78 79 80 |
# File 'lib/vedeu/repositories/store.rb', line 78 def in_memory {} end |
#present?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable has a useful value.
#registered ⇒ Array
Returns a collection of the names of all the registered entities.
41 42 43 44 45 46 47 |
# File 'lib/vedeu/repositories/store.rb', line 41 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.
52 53 54 55 56 57 |
# File 'lib/vedeu/repositories/store.rb', line 52 def reset Vedeu.log(type: :reset, message: "(#{self.class.name}) #{registered.inspect}".freeze) @storage = in_memory end |
#size ⇒ Fixnum
Return the number of entries stored.
64 65 66 |
# File 'lib/vedeu/repositories/store.rb', line 64 def size storage.size end |
#snake_case(name) ⇒ String Originally defined in module Common
Converts a class name to a lowercase snake case string.
#storage ⇒ Array|Hash|Set Also known as: all
Return whole repository; provides raw access to the storage for this repository.
72 73 74 |
# File 'lib/vedeu/repositories/store.rb', line 72 def storage @storage ||= in_memory end |