Class: MightyJSON::Type::Literal
- Inherits:
-
Object
- Object
- MightyJSON::Type::Literal
- Defined in:
- lib/mighty_json/type.rb
Instance Method Summary collapse
- #compile(var:, path:) ⇒ Object
-
#initialize(value) ⇒ Literal
constructor
A new instance of Literal.
- #to_s ⇒ Object
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_s ⇒ Object
102 103 104 |
# File 'lib/mighty_json/type.rb', line 102 def to_s "literal(#{@value})" end |