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.
8
9
10
11
12
13
|
# File 'lib/rollbar/lazy_store.rb', line 8
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
73
74
75
76
77
|
# File 'lib/rollbar/lazy_store.rb', line 73
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.
6
7
8
|
# File 'lib/rollbar/lazy_store.rb', line 6
def raw
@raw
end
|
Instance Method Details
#==(other) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/rollbar/lazy_store.rb', line 23
def ==(other)
if other.is_a?(self.class)
raw == other.raw
else
raw == other
end
end
|
#[](key) ⇒ Object
36
37
38
|
# File 'lib/rollbar/lazy_store.rb', line 36
def [](key)
load_value(key)
end
|
#[]=(key, value) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/rollbar/lazy_store.rb', line 40
def []=(key, value)
raw[key] = value
loaded_data.delete(key)
value
end
|
#clone ⇒ Object
With this version of clone we ensure that the loaded_data is empty
32
33
34
|
# File 'lib/rollbar/lazy_store.rb', line 32
def clone
self.class.new(raw.clone)
end
|
#data ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/rollbar/lazy_store.rb', line 48
def data
raw.reduce({}) do |acc, (k, _)|
acc[k] = self[k]
acc
end
end
|
#eql?(other) ⇒ Boolean
15
16
17
18
19
20
21
|
# File 'lib/rollbar/lazy_store.rb', line 15
def eql?(other)
if other.is_a?(self.class)
raw.eql?(other.raw)
else
raw.eql?(other)
end
end
|