Class: Asynchronic::DataStore::ScopedStore
- Inherits:
-
Object
- Object
- Asynchronic::DataStore::ScopedStore
show all
- Includes:
- Helper
- Defined in:
- lib/asynchronic/data_store/scoped_store.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helper
#clear, #each, #lazy, #lazy?, #merge, #no_lazy, #readonly, #readonly?, #scoped
Constructor Details
#initialize(data_store, scope) ⇒ ScopedStore
Returns a new instance of ScopedStore.
14
15
16
17
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 14
def initialize(data_store, scope)
@data_store = data_store
@scope = Key[scope]
end
|
Instance Attribute Details
#data_store ⇒ Object
Returns the value of attribute data_store.
7
8
9
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 7
def data_store
@data_store
end
|
#scope ⇒ Object
Returns the value of attribute scope.
7
8
9
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 7
def scope
@scope
end
|
Class Method Details
.connect(options) ⇒ Object
9
10
11
12
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 9
def self.connect(options)
data_store = options[:data_store_class].connect(*options[:data_store_connection_args])
new data_store, options[:scope]
end
|
Instance Method Details
#[](key) ⇒ Object
19
20
21
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 19
def [](key)
data_store[scope[key]]
end
|
#[]=(key, value) ⇒ Object
23
24
25
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 23
def []=(key, value)
data_store[scope[key]] = value
end
|
#connection_args ⇒ Object
45
46
47
48
49
50
51
52
53
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 45
def connection_args
[
{
data_store_class: data_store.class,
data_store_connection_args: data_store.connection_args,
scope: scope
}
]
end
|
#delete(key) ⇒ Object
27
28
29
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 27
def delete(key)
data_store.delete scope[key]
end
|
#delete_cascade ⇒ Object
31
32
33
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 31
def delete_cascade
data_store.delete_cascade scope
end
|
#keys ⇒ Object
35
36
37
38
39
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 35
def keys
data_store.keys
.select { |k| k.start_with? scope[''] }
.map { |k| Key[k].remove_first scope.sections.count }
end
|
#synchronize(key, &block) ⇒ Object
41
42
43
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 41
def synchronize(key, &block)
data_store.synchronize(key, &block)
end
|
#to_s ⇒ Object
55
56
57
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 55
def to_s
"#<#{self.class} @data_store=#{data_store} @scope=#{scope}>"
end
|