Class: StrongJSON::Type::Literal
- Inherits:
-
Object
- Object
- StrongJSON::Type::Literal
- Defined in:
- lib/strong_json/type.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #coerce(value, path: ErrorPath.root(self)) ⇒ Object
-
#initialize(value) ⇒ Literal
constructor
A new instance of Literal.
- #to_s ⇒ Object
Methods included from WithAlias
Methods included from Match
Constructor Details
#initialize(value) ⇒ Literal
Returns a new instance of Literal.
129 130 131 |
# File 'lib/strong_json/type.rb', line 129 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
127 128 129 |
# File 'lib/strong_json/type.rb', line 127 def value @value end |
Instance Method Details
#==(other) ⇒ Object
142 143 144 145 146 |
# File 'lib/strong_json/type.rb', line 142 def ==(other) if other.is_a?(Literal) other.value == value end end |
#coerce(value, path: ErrorPath.root(self)) ⇒ Object
137 138 139 140 |
# File 'lib/strong_json/type.rb', line 137 def coerce(value, path: ErrorPath.root(self)) raise TypeError.new(path: path, value: value) unless (_ = self.value) == value value end |
#to_s ⇒ Object
133 134 135 |
# File 'lib/strong_json/type.rb', line 133 def to_s self.alias&.to_s || (_ = @value).inspect end |