Class: ActiveRecord::Refined::AST::JsonBuild

Inherits:
Node
  • Object
show all
Includes:
ComputedJson, JsonComparable, Predications
Defined in:
lib/active_record/refined/ast.rb

Overview

A JSON document built in the row: json_array from the values given, json_object from a Ruby hash. SQLite and the MySQL family both say the standard names; PostgreSQL is asked to build jsonb, whose documents the other JSON operations here read.

Constant Summary collapse

NAMES =
{
  array: { postgresql: "jsonb_build_array" },
  object: { postgresql: "jsonb_build_object" },
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ComputedJson

#json_value?

Methods included from JsonComparable

#between?, #in?, #not_between?, #not_in?, #~

Methods included from Predications

#!=, #!~, #<, #<=, #==, #=~, #>, #>=, #between?, #bury, #casecmp?, #contains?, #dig, #dig_text, #distinct_from?, #end_with?, #except, #false?, #ilike?, #in?, #include?, #intersect?, #key?, #keys, #like?, #member?, #not_between?, #not_distinct_from?, #not_false?, #not_ilike?, #not_in?, #not_like?, #not_null?, #not_true?, #null?, #start_with?, #subset?, #superset?, #true?, #when

Methods inherited from Node

#as, #asc, #desc

Constructor Details

#initialize(kind, values) ⇒ JsonBuild

Returns a new instance of JsonBuild.



1123
1124
1125
1126
# File 'lib/active_record/refined/ast.rb', line 1123

def initialize(kind, values)
  @kind = kind
  @values = kind == :object ? check_pairs(values) : values
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



1121
1122
1123
# File 'lib/active_record/refined/ast.rb', line 1121

def kind
  @kind
end

#valuesObject (readonly)

Returns the value of attribute values.



1121
1122
1123
# File 'lib/active_record/refined/ast.rb', line 1121

def values
  @values
end

Instance Method Details

#to_arel(table, model) ⇒ Object



1128
1129
1130
1131
1132
# File 'lib/active_record/refined/ast.rb', line 1128

def to_arel(table, model)
  Arel::Nodes::NamedFunction.new(
    NAMES.fetch(kind).fetch(AST.adapter_family(model)) { "JSON_#{kind.to_s.upcase}" },
    arguments(table, model))
end