Sha256: 5bf69522ccdc1388a7a167aaddb155f0dfb3485e7fcd6152efc3c749578316a3

Contents?: true

Size: 579 Bytes

Versions: 3

Compression:

Stored size: 579 Bytes

Contents

require "set"

require "membrane/errors"
require "membrane/schemas/base"

class Membrane::Schemas::Bool < Membrane::Schemas::Base
  def validate(object)
    BoolValidator.new(object).validate
  end

  class BoolValidator
    TRUTH_VALUES = Set.new([true, false])

    def initialize(object)
      @object = object
    end

    def validate
      fail!(@object) if !TRUTH_VALUES.include?(@object)
    end

    private

    def fail!(object)
      emsg = "Expected instance of true or false, given #{object}"
      raise Membrane::SchemaValidationError.new(emsg)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
membrane-1.1.0 lib/membrane/schemas/bool.rb
membrane-1.0.0 lib/membrane/schemas/bool.rb
membrane-0.0.5 lib/membrane/schemas/bool.rb