Class: Tabry::Models::ConfigList
- Inherits:
-
Object
- Object
- Tabry::Models::ConfigList
show all
- Includes:
- Enumerable
- Defined in:
- lib/tabry/models/config_list.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(raw:, root:, klass:) ⇒ ConfigList
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/tabry/models/config_list.rb', line 12
def initialize(raw:, root:, klass:)
raise "missing root" unless root
raw ||= []
unless raw.is_a?(Array)
raise ConfigError, "#{self.class.name} must be an array. Got #{raw.class}"
end
@unflattened = raw.map { |a| klass.new(raw: a, root: root) }
end
|
Instance Attribute Details
#unflattened ⇒ Object
Returns the value of attribute unflattened.
8
9
10
|
# File 'lib/tabry/models/config_list.rb', line 8
def unflattened
@unflattened
end
|
Instance Method Details
#[](*args) ⇒ Object
36
37
38
|
# File 'lib/tabry/models/config_list.rb', line 36
def [](*args)
to_a.[](*args)
end
|
#as_json ⇒ Object
27
28
29
30
|
# File 'lib/tabry/models/config_list.rb', line 27
def as_json
val = to_a.map { ConfigObject.as_json(_1) }
val.empty? ? nil : val
end
|
#each(&blk) ⇒ Object
40
41
42
|
# File 'lib/tabry/models/config_list.rb', line 40
def each(&blk)
to_a.each(&blk)
end
|
#empty? ⇒ Boolean
48
49
50
|
# File 'lib/tabry/models/config_list.rb', line 48
def empty?
to_a.empty?
end
|
#flatten ⇒ Object
32
33
34
|
# File 'lib/tabry/models/config_list.rb', line 32
def flatten
@flatten ||= unflattened.map(&:flatten).flatten
end
|
#length ⇒ Object
44
45
46
|
# File 'lib/tabry/models/config_list.rb', line 44
def length
to_a.length
end
|
#to_a ⇒ Object
23
24
25
|
# File 'lib/tabry/models/config_list.rb', line 23
def to_a
flatten
end
|