Class: StrongJSON::Type::Literal

Inherits:
Object
  • Object
show all
Includes:
Match
Defined in:
lib/strong_json/type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Match

#===, #=~

Constructor Details

#initialize(value) ⇒ Literal

Returns a new instance of Literal.



94
95
96
# File 'lib/strong_json/type.rb', line 94

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



92
93
94
# File 'lib/strong_json/type.rb', line 92

def value
  @value
end

Instance Method Details

#coerce(value, path: []) ⇒ Object

Raises:



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

def coerce(value, path: [])
  raise Error.new(path: path, type: self, value: value) unless (_ = self.value) == value
  value
end

#to_sObject



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

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