Class: Praxis::Mapper::Support::MemoryRepository
- Inherits:
-
Object
- Object
- Praxis::Mapper::Support::MemoryRepository
- Defined in:
- lib/praxis-mapper/support/memory_repository.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
readonly
Returns the value of attribute collections.
Instance Method Summary collapse
-
#all(collection, **conditions) ⇒ Object
Retrieve all records for
collectionmatching allconditions. - #clear! ⇒ Object
- #collection(collection) ⇒ Object
-
#initialize ⇒ MemoryRepository
constructor
A new instance of MemoryRepository.
- #insert(collection, *values) ⇒ Object
Constructor Details
#initialize ⇒ MemoryRepository
Returns a new instance of MemoryRepository.
9 10 11 |
# File 'lib/praxis-mapper/support/memory_repository.rb', line 9 def initialize clear! end |
Instance Attribute Details
#collections ⇒ Object (readonly)
Returns the value of attribute collections.
7 8 9 |
# File 'lib/praxis-mapper/support/memory_repository.rb', line 7 def collections @collections end |
Instance Method Details
#all(collection, **conditions) ⇒ Object
Retrieve all records for collection matching all conditions.
34 35 36 37 38 39 40 |
# File 'lib/praxis-mapper/support/memory_repository.rb', line 34 def all(collection, **conditions) self.collection(collection).select do |row| conditions.all? do |k,v| row[k] === v end end end |
#clear! ⇒ Object
13 14 15 16 17 |
# File 'lib/praxis-mapper/support/memory_repository.rb', line 13 def clear! @collections = Hash.new do |hash, collection_name| hash[collection_name] = Set.new end end |
#collection(collection) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/praxis-mapper/support/memory_repository.rb', line 19 def collection(collection) collection_name = if collection.respond_to?(:table_name) collection.table_name.to_sym else collection.to_sym end @collections[collection_name] end |
#insert(collection, *values) ⇒ Object
29 30 31 |
# File 'lib/praxis-mapper/support/memory_repository.rb', line 29 def insert(collection, *values) self.collection(collection).merge(*values) end |