Module: Qwack::BaseArray
- Includes:
- Base
- Defined in:
- lib/qwack/base_array.rb
Overview
Base module for user defined arrays
Instance Method Summary collapse
- #allowed_types ⇒ Object
- #mock(input = nil) ⇒ Object
- #own_allowed_types ⇒ Object
- #validation_errors(input, path = 'root') ⇒ Object
Methods included from Base
Instance Method Details
#allowed_types ⇒ Object
10 11 12 13 14 15 |
# File 'lib/qwack/base_array.rb', line 10 def allowed_types ancestors.reverse.each_with_object([]) do |ancestor, obj| obj.append(*ancestor.own_allowed_types) \ if ancestor.respond_to?(:own_allowed_types) end end |
#mock(input = nil) ⇒ Object
33 34 35 |
# File 'lib/qwack/base_array.rb', line 33 def mock(input = nil) input || [own_allowed_types.first&.mock] end |
#own_allowed_types ⇒ Object
17 18 19 |
# File 'lib/qwack/base_array.rb', line 17 def own_allowed_types @own_allowed_types ||= [] end |
#validation_errors(input, path = 'root') ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/qwack/base_array.rb', line 21 def validation_errors(input, path = 'root') return [{ path: path, name: name, desc: 'Is not an array', item: input }] \ unless input.is_a?(::Array) all_allowed_types = allowed_types input.each_with_object([]).with_index do |(item, errors), index| all_allowed_types.each do |type| errors.append(*type.validation_errors(item, "#{path}.#{index}")) end end end |