Class: WCC::Contentful::Store::MemoryStore
- Defined in:
- lib/wcc/contentful/store/memory_store.rb
Defined Under Namespace
Classes: Query
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #find(key) ⇒ Object
- #find_all(content_type:) ⇒ Object
-
#initialize ⇒ MemoryStore
constructor
A new instance of MemoryStore.
- #keys ⇒ Object
- #set(key, value) ⇒ Object
Methods inherited from Base
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 super @hash = {} end |
Instance Method Details
#delete(key) ⇒ Object
19 20 21 22 23 |
# File 'lib/wcc/contentful/store/memory_store.rb', line 19 def delete(key) mutex.with_write_lock do @hash.delete(key) end end |
#find(key) ⇒ Object
29 30 31 32 33 |
# File 'lib/wcc/contentful/store/memory_store.rb', line 29 def find(key) mutex.with_read_lock do @hash[key] end end |
#find_all(content_type:) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/wcc/contentful/store/memory_store.rb', line 35 def find_all(content_type:) relation = mutex.with_read_lock { @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 |
#keys ⇒ Object
25 26 27 |
# File 'lib/wcc/contentful/store/memory_store.rb', line 25 def keys mutex.with_read_lock { @hash.keys } end |
#set(key, value) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/wcc/contentful/store/memory_store.rb', line 10 def set(key, value) value = value.deep_dup.freeze mutex.with_write_lock do old = @hash[key] @hash[key] = value old end end |