Class: WCC::Contentful::Store::MemoryStore
- Inherits:
-
Object
- Object
- WCC::Contentful::Store::MemoryStore
- Defined in:
- lib/wcc/contentful/store/memory_store.rb
Defined Under Namespace
Classes: Query
Instance Method Summary collapse
- #find(key) ⇒ Object
- #find_all ⇒ Object
- #find_by(content_type:) ⇒ Object
- #index(key, value) ⇒ Object
-
#initialize ⇒ MemoryStore
constructor
A new instance of MemoryStore.
- #keys ⇒ Object
Constructor Details
#initialize ⇒ MemoryStore
Returns a new instance of MemoryStore.
5 6 7 8 |
# File 'lib/wcc/contentful/store/memory_store.rb', line 5 def initialize @hash = {} @mutex = Mutex.new end |
Instance Method Details
#find(key) ⇒ Object
21 22 23 24 25 |
# File 'lib/wcc/contentful/store/memory_store.rb', line 21 def find(key) @mutex.synchronize do @hash[key] end end |
#find_all ⇒ Object
27 28 29 |
# File 'lib/wcc/contentful/store/memory_store.rb', line 27 def find_all Query.new(@mutex.synchronize { @hash.values }) end |
#find_by(content_type:) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wcc/contentful/store/memory_store.rb', line 31 def find_by(content_type:) relation = @mutex.synchronize { @hash.values } relation = relation.reject do |v| value_content_type = v.dig('sys', 'contentType', 'sys', 'id') value_content_type.nil? || value_content_type != content_type end Query.new(relation) end |
#index(key, value) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/wcc/contentful/store/memory_store.rb', line 10 def index(key, value) value = value.deep_dup.freeze @mutex.synchronize do @hash[key] = value end end |
#keys ⇒ Object
17 18 19 |
# File 'lib/wcc/contentful/store/memory_store.rb', line 17 def keys @mutex.synchronize { @hash.keys } end |