Class: KeyVortex::Adapter::Memory
- Inherits:
-
KeyVortex::Adapter
- Object
- KeyVortex::Adapter
- KeyVortex::Adapter::Memory
- Defined in:
- lib/key_vortex/adapter/memory.rb
Overview
An in-memory implementation of an adapter. While typically not useful in production, it can provide a convenient implementation for unit testing.
Class Method Summary collapse
-
.build(items: {}, limitations: []) ⇒ KeyVortex::Adapter::Memory
A pass-through to the constructor which is used by KeyVortex.vortex.
Instance Method Summary collapse
-
#find(key) ⇒ Record?
The record with Record#key set to key.
-
#initialize(items, limitations: []) ⇒ Memory
constructor
Create a new instance of the in-memory adapter.
-
#remove(key) ⇒ Object
Remove the record with Record#key set to key.
-
#save(record) ⇒ Object
Save the record to the provided hash using Record#key as the key.
Methods inherited from KeyVortex::Adapter
#limitation_for, #register_limitation, symbol
Constructor Details
#initialize(items, limitations: []) ⇒ Memory
Create a new instance of the in-memory adapter. By default, it has no limitations, but since it’s most likely testing an adapter which is more restrictive, it accepts a list of limitations to apply.
27 28 29 30 31 |
# File 'lib/key_vortex/adapter/memory.rb', line 27 def initialize(items, limitations: []) super() @items = items limitations.each { |limit| register_limitation(limit) } end |
Class Method Details
.build(items: {}, limitations: []) ⇒ KeyVortex::Adapter::Memory
A pass-through to the constructor which is used by KeyVortex.vortex.
17 18 19 |
# File 'lib/key_vortex/adapter/memory.rb', line 17 def self.build(items: {}, limitations: []) new(items, limitations: limitations) end |
Instance Method Details
#find(key) ⇒ Record?
Returns The record with Record#key set to key.
42 43 44 |
# File 'lib/key_vortex/adapter/memory.rb', line 42 def find(key) @items[key] end |
#remove(key) ⇒ Object
Remove the record with Record#key set to key
47 48 49 |
# File 'lib/key_vortex/adapter/memory.rb', line 47 def remove(key) @items.delete(key) end |
#save(record) ⇒ Object
Save the record to the provided hash using Record#key as the key.
36 37 38 |
# File 'lib/key_vortex/adapter/memory.rb', line 36 def save(record) @items[record.key] = record end |