Class: Rollbar::LazyStore
- Inherits:
-
Object
- Object
- Rollbar::LazyStore
show all
- Defined in:
- lib/rollbar/lazy_store.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(initial_data) ⇒ LazyStore
Returns a new instance of LazyStore.
6
7
8
9
10
11
|
# File 'lib/rollbar/lazy_store.rb', line 6
def initialize(initial_data)
initial_data ||= {}
@raw = initial_data
@loaded_data = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *args, &block) ⇒ Object
69
70
71
72
73
|
# File 'lib/rollbar/lazy_store.rb', line 69
def method_missing(method_sym, *args, &block)
return raw.send(method_sym, *args, &block) if raw.respond_to?(method_sym)
super
end
|
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
3
4
5
|
# File 'lib/rollbar/lazy_store.rb', line 3
def raw
@raw
end
|
Instance Method Details
#==(other) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/rollbar/lazy_store.rb', line 21
def ==(other)
raw == if other.is_a?(self.class)
other.raw
else
other
end
end
|
#[](key) ⇒ Object
34
35
36
|
# File 'lib/rollbar/lazy_store.rb', line 34
def [](key)
load_value(key)
end
|
#[]=(key, value) ⇒ Object
38
39
40
41
42
|
# File 'lib/rollbar/lazy_store.rb', line 38
def []=(key, value)
raw[key] = value
loaded_data.delete(key)
end
|
#clone ⇒ Object
With this version of clone we ensure that the loaded_data is empty
30
31
32
|
# File 'lib/rollbar/lazy_store.rb', line 30
def clone
self.class.new(raw.clone)
end
|
#data ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/rollbar/lazy_store.rb', line 44
def data
raw.reduce({}) do |acc, (k, _)|
acc[k] = self[k]
acc
end
end
|
#eql?(other) ⇒ Boolean
13
14
15
16
17
18
19
|
# File 'lib/rollbar/lazy_store.rb', line 13
def eql?(other)
if other.is_a?(self.class)
raw.eql?(other.raw)
else
raw.eql?(other)
end
end
|