Class: CommandTower::Deserializers::Clients::Types::ArrayType
- Defined in:
- app/deserializers/command_tower/deserializers/clients/types.rb
Instance Method Summary collapse
- #call(value, path:) ⇒ Object
- #expected_label ⇒ Object
-
#initialize(element_type) ⇒ ArrayType
constructor
A new instance of ArrayType.
Constructor Details
#initialize(element_type) ⇒ ArrayType
Returns a new instance of ArrayType.
174 175 176 |
# File 'app/deserializers/command_tower/deserializers/clients/types.rb', line 174 def initialize(element_type) @element_type = element_type end |
Instance Method Details
#call(value, path:) ⇒ Object
178 179 180 181 182 183 184 185 186 187 |
# File 'app/deserializers/command_tower/deserializers/clients/types.rb', line 178 def call(value, path:) unless value.is_a?(Array) reject!(path, value, "array", "expected Array") end value.each_with_index.map do |item, index| member_path = path.empty? ? "[#{index}]" : "#{path}[#{index}]" @element_type.call(item, path: member_path) end end |
#expected_label ⇒ Object
189 190 191 |
# File 'app/deserializers/command_tower/deserializers/clients/types.rb', line 189 def expected_label "array" end |