Class: Membrane::Schema::List
Instance Attribute Summary collapse
-
#elem_schema ⇒ Object
readonly
Returns the value of attribute elem_schema.
Instance Method Summary collapse
-
#initialize(elem_schema) ⇒ List
constructor
A new instance of List.
- #validate(object) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(elem_schema) ⇒ List
Returns a new instance of List.
12 13 14 |
# File 'lib/membrane/schema/list.rb', line 12 def initialize(elem_schema) @elem_schema = elem_schema end |
Instance Attribute Details
#elem_schema ⇒ Object (readonly)
Returns the value of attribute elem_schema.
10 11 12 |
# File 'lib/membrane/schema/list.rb', line 10 def elem_schema @elem_schema end |
Instance Method Details
#validate(object) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/membrane/schema/list.rb', line 16 def validate(object) if !object.kind_of?(Array) emsg = "Expected instance of Array, given instance of #{object.class}" raise Membrane::SchemaValidationError.new(emsg) end errors = {} object.each_with_index do |elem, ii| begin @elem_schema.validate(elem) rescue Membrane::SchemaValidationError => e errors[ii] = e.to_s end end if errors.size > 0 emsg = errors.map { |ii, e| "At index #{ii}: #{e}" }.join(", ") raise Membrane::SchemaValidationError.new(emsg) end end |