Class: ActiveRecord::Refined::AST::JsonKeys

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

Overview

The keys of a JSON document, as Hash#keys gives them: a JSON array. Only the MySQL family has a function for it; the other two reach the same array through a subquery over their key-listing functions. The type guard is what makes all four answer alike: the keys of what is not an object are NULL rather than SQLite's array indices or PostgreSQL's error, and the keys of {} are [] rather than PostgreSQL's NULL, jsonb_agg over no rows.

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, #collate, #desc

Constructor Details

#initialize(operand) ⇒ JsonKeys

Returns a new instance of JsonKeys.



1165
1166
1167
# File 'lib/active_record/refined/ast.rb', line 1165

def initialize(operand)
  @operand = operand
end

Instance Attribute Details

#operandObject (readonly)

Returns the value of attribute operand.



1163
1164
1165
# File 'lib/active_record/refined/ast.rb', line 1163

def operand
  @operand
end

Instance Method Details

#to_arel(table, model) ⇒ Object



1169
1170
1171
# File 'lib/active_record/refined/ast.rb', line 1169

def to_arel(table, model)
  Dialect.for(model).json_keys(to_arel_operand(operand, table, model), model)
end