Class: Tabry::Models::ConfigStringHash
- Inherits:
-
Object
- Object
- Tabry::Models::ConfigStringHash
show all
- Includes:
- Enumerable
- Defined in:
- lib/tabry/models/config_string_hash.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(raw:, root:, klass:) ⇒ ConfigStringHash
Returns a new instance of ConfigStringHash.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/tabry/models/config_string_hash.rb', line 12
def initialize(raw:, root:, klass:)
@_raw = raw
@_root = root
raw ||= {}
unless raw.is_a?(Hash)
raise ConfigError, "#{self.class.name} must be a Hash. Got #{raw.class}"
end
unless raw.keys.all? { |k| k.is_a?(String) }
raise ConfigError, "#{self.class.name} keys must all be string keys."
end
@to_h = raw.transform_values { |a| klass.new(raw: a, root: root) }
end
|
Instance Attribute Details
#_raw ⇒ Object
Returns the value of attribute _raw.
8
9
10
|
# File 'lib/tabry/models/config_string_hash.rb', line 8
def _raw
@_raw
end
|
#_root ⇒ Object
Returns the value of attribute _root.
8
9
10
|
# File 'lib/tabry/models/config_string_hash.rb', line 8
def _root
@_root
end
|
#to_h ⇒ Object
Returns the value of attribute to_h.
8
9
10
|
# File 'lib/tabry/models/config_string_hash.rb', line 8
def to_h
@to_h
end
|
Instance Method Details
#[](*args) ⇒ Object
27
28
29
|
# File 'lib/tabry/models/config_string_hash.rb', line 27
def [](*args)
to_h.[](*args)
end
|
#as_json ⇒ Object
43
44
45
46
|
# File 'lib/tabry/models/config_string_hash.rb', line 43
def as_json
val = to_h.transform_values { ConfigObject.as_json(_1) }
val.empty? ? nil : val
end
|
#each(&blk) ⇒ Object
31
32
33
|
# File 'lib/tabry/models/config_string_hash.rb', line 31
def each(&blk)
to_h.each(&blk)
end
|
#empty? ⇒ Boolean
35
36
37
|
# File 'lib/tabry/models/config_string_hash.rb', line 35
def empty?
to_h.empty?
end
|
#keys ⇒ Object
39
40
41
|
# File 'lib/tabry/models/config_string_hash.rb', line 39
def keys
to_h.keys
end
|