Sha256: 04b1611588d19a6c44265a71d919f8480ec8b44e4311c6e53c2b3831b28f8277
Contents?: true
Size: 813 Bytes
Versions: 2
Compression:
Stored size: 813 Bytes
Contents
require "membrane/errors" require "membrane/schema/base" module Membrane module Schema end end class Membrane::Schema::List < Membrane::Schema::Base attr_reader :elem_schema def initialize(elem_schema) @elem_schema = elem_schema end 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 end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
membrane-0.0.2 | lib/membrane/schema/list.rb |
membrane-0.0.1 | lib/membrane/schema/list.rb |