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.
10
11
12
13
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 10
def initialize(data_store, scope)
@data_store = data_store
@scope = Key.new 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.
8
9
10
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 8
def scope
@scope
end
|
Class Method Details
.connect(*args) ⇒ Object
47
48
49
50
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 47
def self.connect(*args)
data_store = args[0][:data_store_class].connect *args[0][:data_store_connection_args]
new data_store, args[0][:scope]
end
|
Instance Method Details
#[](key) ⇒ Object
15
16
17
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 15
def [](key)
@data_store[@scope[key]]
end
|
#[]=(key, value) ⇒ Object
19
20
21
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 19
def []=(key, value)
@data_store[@scope[key]] = value
end
|
#connection_args ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 37
def connection_args
[
{
data_store_class: @data_store.class,
data_store_connection_args: @data_store.connection_args,
scope: @scope
}
]
end
|
#delete(key) ⇒ Object
23
24
25
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 23
def delete(key)
@data_store.delete @scope[key]
end
|
#keys ⇒ Object
27
28
29
30
31
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 27
def keys
@data_store.keys.
select { |k| k.start_with? @scope[''] }.
map { |k| Key.new(k).remove_first @scope.sections.count }
end
|
#synchronize(key, &block) ⇒ Object
33
34
35
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 33
def synchronize(key, &block)
data_store.synchronize(key, &block)
end
|
#to_s ⇒ Object
52
53
54
|
# File 'lib/asynchronic/data_store/scoped_store.rb', line 52
def to_s
"#<#{self.class} @data_store=#{@data_store} @scope=#{@scope}>"
end
|