Class: Dhall::Coder::Verifier

Inherits:
Object
  • Object
show all
Defined in:
lib/dhall/coder.rb

Instance Method Summary collapse

Constructor Details

#initialize(*classes) ⇒ Verifier

Returns a new instance of Verifier.



14
15
16
17
# File 'lib/dhall/coder.rb', line 14

def initialize(*classes)
  @classes = classes
  @matcher = ValueSemantics::Either.new(classes)
end

Instance Method Details

#verify(obj, op) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/dhall/coder.rb', line 28

def verify(obj, op)
  if @matcher === obj
    obj
  else
    raise ArgumentError, "#{op} does not match "\
                         "#{@classes.inspect}: #{obj.inspect}"
  end
end

#verify_class(klass, op) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/dhall/coder.rb', line 19

def verify_class(klass, op)
  if @classes.any? { |safe| klass <= safe }
    klass
  else
    raise ArgumentError, "#{op} does not match "\
                         "#{@classes.inspect}: #{klass}"
  end
end