Class: Adalog::InMemoryRepo
- Inherits:
-
Object
- Object
- Adalog::InMemoryRepo
- Defined in:
- lib/adalog/in_memory_repo.rb
Instance Attribute Summary collapse
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
- #all ⇒ Object
- #clear! ⇒ Object
- #fetch(**options) ⇒ Object
-
#initialize(**repo_options) ⇒ InMemoryRepo
constructor
A new instance of InMemoryRepo.
- #insert(entry = nil, **options) ⇒ Object
Constructor Details
#initialize(**repo_options) ⇒ InMemoryRepo
Returns a new instance of InMemoryRepo.
6 7 8 |
# File 'lib/adalog/in_memory_repo.rb', line 6 def initialize(**) @storage = Array.new end |
Instance Attribute Details
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
4 5 6 |
# File 'lib/adalog/in_memory_repo.rb', line 4 def storage @storage end |
Instance Method Details
#all ⇒ Object
33 34 35 |
# File 'lib/adalog/in_memory_repo.rb', line 33 def all storage.dup end |
#clear! ⇒ Object
27 28 29 30 |
# File 'lib/adalog/in_memory_repo.rb', line 27 def clear! @storage = Array.new :ok end |
#fetch(**options) ⇒ Object
11 12 13 |
# File 'lib/adalog/in_memory_repo.rb', line 11 def fetch(**) all end |
#insert(entry = nil, **options) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/adalog/in_memory_repo.rb', line 16 def insert(entry = nil, **) converted_entry = Adalog::Entry.build(entry = nil, **) if converted_entry.valid? storage.unshift(converted_entry) [:ok, converted_entry] else [:error, converted_entry.errors] end end |