Sha256: 3af18737aceb31d19cbb973b029287c4b1546a6022760515b6d99164de742c6f

Contents?: true

Size: 669 Bytes

Versions: 2

Compression:

Stored size: 669 Bytes

Contents

require "membrane/errors"
require "membrane/schema/base"

module Membrane
  module Schema
  end
end

class Membrane::Schema::Enum < Membrane::Schema::Base
  attr_reader :elem_schemas

  def initialize(*elem_schemas)
    @elem_schemas = elem_schemas
    @elem_schema_str = elem_schemas.map { |s| s.to_s }.join(", ")
  end

  def validate(object)
    @elem_schemas.each do |schema|
      begin
        schema.validate(object)
        return nil
      rescue Membrane::SchemaValidationError
      end
    end

    emsg = "Object #{object} doesn't validate" \
           + " against any of #{@elem_schema_str}"
    raise Membrane::SchemaValidationError.new(emsg)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
membrane-0.0.2 lib/membrane/schema/enum.rb
membrane-0.0.1 lib/membrane/schema/enum.rb