Class: ECG::Store
- Inherits:
-
Object
show all
- Defined in:
- lib/ecg/store.rb
Instance Method Summary
collapse
Constructor Details
#initialize(hash) ⇒ Store
Returns a new instance of Store.
5
6
7
8
|
# File 'lib/ecg/store.rb', line 5
def initialize(hash)
map = hash.map { |k, v| [k.to_sym, transform_value(v)] }
@store = map.to_h
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/ecg/store.rb', line 24
def method_missing(name, *args)
name = name.to_sym
if @store.key?(name)
transform_value(@store[name])
elsif @store.respond_to?(name)
@store.public_send(name, *args)
else
super
end
end
|
Instance Method Details
#==(other) ⇒ Object
51
52
53
54
55
|
# File 'lib/ecg/store.rb', line 51
def ==(other)
return false unless other.is_a?(self.class)
to_h == other.to_h
end
|
#binding ⇒ Object
15
16
17
|
# File 'lib/ecg/store.rb', line 15
def binding
super
end
|
#initialize_copy(obj) ⇒ Object
10
11
12
13
|
# File 'lib/ecg/store.rb', line 10
def initialize_copy(obj)
super
@store = @store.dup
end
|
#inspect ⇒ Object
19
20
21
22
|
# File 'lib/ecg/store.rb', line 19
def inspect
detail = @store.map { |k, v| " @#{k}=#{v.inspect}" }.join(',')
"#<#{self.class}:#{object_id << 1}#{detail}>"
end
|
#respond_to_missing?(symbol, include_private = false) ⇒ Boolean
36
37
38
39
40
|
# File 'lib/ecg/store.rb', line 36
def respond_to_missing?(symbol, include_private = false)
symbol = symbol.to_sym
@store.key?(symbol) || @store.respond_to?(symbol) || super
end
|
#to_h ⇒ Object
42
43
44
|
# File 'lib/ecg/store.rb', line 42
def to_h
@store.transform_values(&method(:intransform_value))
end
|
#to_json(*args) ⇒ Object
46
47
48
49
|
# File 'lib/ecg/store.rb', line 46
def to_json(*args)
require 'json'
to_h.to_json(args)
end
|