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)
else
super
end
end
|
Instance Method Details
#binding ⇒ Object
15
16
17
|
# File 'lib/ecg/store.rb', line 15
def binding
super end
|
#initialize_copy ⇒ Object
10
11
12
13
|
# File 'lib/ecg/store.rb', line 10
def initialize_copy
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}#{detail}>"
end
|
#respond_to_missing?(symbol, include_private = false) ⇒ Boolean
36
37
38
|
# File 'lib/ecg/store.rb', line 36
def respond_to_missing?(symbol, include_private = false)
@store&.key?(symbol.to_sym) || super
end
|
#to_h ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/ecg/store.rb', line 40
def to_h
@store.transform_values do |v|
case v
when self.class then v.to_h
when Array then v.map(&:to_h)
else v
end
end
end
|
#to_json(*args) ⇒ Object
50
51
52
53
|
# File 'lib/ecg/store.rb', line 50
def to_json(*args)
require 'json'
to_h.to_json(args)
end
|