Sha256: 84d5def04682398b0053f71aa13cd9524852ad24cf2b4e41f41a4ee762477d1d
Contents?: true
Size: 719 Bytes
Versions: 1
Compression:
Stored size: 719 Bytes
Contents
require "membrane/errors" require "membrane/schemas/base" class Membrane::Schemas::Class < Membrane::Schemas::Base attr_reader :klass def initialize(klass) @klass = klass end # Validates whether or not the supplied object is derived from klass def validate(object) ClassValidator.new(@klass, object).validate end class ClassValidator def initialize(klass, object) @klass = klass @object = object end def validate fail! if !@object.kind_of?(@klass) end private def fail! emsg = "Expected instance of #{@klass}," \ + " given an instance of #{@object.class}" raise Membrane::SchemaValidationError.new(emsg) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
membrane-0.0.4 | lib/membrane/schemas/class.rb |