Class: Definition::Types::Each
- Defined in:
- lib/definition/types/each.rb
Instance Attribute Summary collapse
-
#item_definition ⇒ Object
Returns the value of attribute item_definition.
Attributes inherited from Base
Instance Method Summary collapse
- #conform(values) ⇒ Object
- #error_renderer ⇒ Object
-
#initialize(name, definition:) ⇒ Each
constructor
A new instance of Each.
Methods inherited from Base
Constructor Details
#initialize(name, definition:) ⇒ Each
Returns a new instance of Each.
11 12 13 14 |
# File 'lib/definition/types/each.rb', line 11 def initialize(name, definition:) self.item_definition = definition super(name) end |
Instance Attribute Details
#item_definition ⇒ Object
Returns the value of attribute item_definition.
9 10 11 |
# File 'lib/definition/types/each.rb', line 9 def item_definition @item_definition end |
Instance Method Details
#conform(values) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/definition/types/each.rb', line 16 def conform(values) return non_array_error(values) unless values.is_a?(Array) errors = false results = values.map do |value| result = item_definition.conform(value) errors = true unless result.passed? result end return ConformResult.new(results.map(&:value)) unless errors ConformResult.new(values, errors: [ConformError.new(self, "Not all items conform with '#{name}'", sub_errors: convert_errors(results))]) end |
#error_renderer ⇒ Object
34 35 36 |
# File 'lib/definition/types/each.rb', line 34 def error_renderer ErrorRenderers::Leaf end |