Class: ActiveRecord::Refined::AST::JsonLiteral

Inherits:
Node
  • Object
show all
Defined in:
lib/active_record/refined/ast.rb

Overview

A Ruby value on the JSON side of a comparison, which jsonb and MySQL's JSON type answer alike: numbers compare as numbers and documents structurally. SQLite and MariaDB have only the text of each -- spelling and key order deciding what equality means -- and refuse here. PostgreSQL needs no cast, an untyped literal beside a jsonb operand coercing to jsonb; MySQL is told CAST(... AS JSON), since a bare string beside JSON would be a JSON string, and every string outranks every number in its ordering.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#as, #asc, #collate, #desc

Constructor Details

#initialize(value) ⇒ JsonLiteral

Returns a new instance of JsonLiteral.



959
960
961
# File 'lib/active_record/refined/ast.rb', line 959

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



957
958
959
# File 'lib/active_record/refined/ast.rb', line 957

def value
  @value
end

Instance Method Details

#to_arel(_table, model) ⇒ Object



963
964
965
# File 'lib/active_record/refined/ast.rb', line 963

def to_arel(_table, model)
  Dialect.for(model).json_literal(Arel::Nodes.build_quoted(JSON.generate(value)), model)
end