Class: MightyJSON::Type::Literal

Inherits:
Object
  • Object
show all
Defined in:
lib/mighty_json/type.rb

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Literal

Returns a new instance of Literal.



98
99
100
# File 'lib/mighty_json/type.rb', line 98

def initialize(value)
  @value = value
end

Instance Method Details

#compile(var:, path:) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/mighty_json/type.rb', line 106

def compile(var:, path:)
  v = var.cur
  <<~END
    raise Error.new(path: #{path.inspect}, type: #{self.to_s.inspect}, value: #{v}) unless #{@value.inspect} == #{v}
    #{v}
  END
end

#to_sObject



102
103
104
# File 'lib/mighty_json/type.rb', line 102

def to_s
  "literal(#{@value})"
end