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.



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

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



90
91
92
# File 'lib/strong_json/type.rb', line 90

def value
  @value
end

Instance Method Details

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

Raises:



100
101
102
103
# File 'lib/strong_json/type.rb', line 100

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

#to_sObject



96
97
98
# File 'lib/strong_json/type.rb', line 96

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