Class: ActiveRecord::Refined::AST::JsonExcept

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

Overview

Keys taken out of a JSON document. PostgreSQL subtracts them, the other two remove a path apiece.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from JsonSteps

#check_steps, #dollar_path, #dollar_step, #escape_step, #steps_array

Methods included from Predications

#!=, #!~, #<, #<=, #==, #=~, #>, #>=, #between?, #bury, #casecmp?, #contains?, #dig, #dig_json, #distinct_from?, #end_with?, #except, #false?, #ilike?, #in?, #include?, #intersect?, #key?, #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(operand, keys) ⇒ JsonExcept

Returns a new instance of JsonExcept.



691
692
693
694
# File 'lib/active_record/refined/ast.rb', line 691

def initialize(operand, keys)
  @operand = operand
  @keys = check_keys(keys)
end

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



689
690
691
# File 'lib/active_record/refined/ast.rb', line 689

def keys
  @keys
end

#operandObject (readonly)

Returns the value of attribute operand.



689
690
691
# File 'lib/active_record/refined/ast.rb', line 689

def operand
  @operand
end

Instance Method Details

#to_arel(table, model) ⇒ Object



696
697
698
699
700
701
702
703
704
# File 'lib/active_record/refined/ast.rb', line 696

def to_arel(table, model)
  document = to_arel_operand(operand, table, model)
  return Arel::Nodes::InfixOperation.new(:-, document, key_array) if
    AST.adapter_family(model) == :postgresql

  Arel::Nodes::NamedFunction.new(
    'JSON_REMOVE',
    [document, *keys.map {|key| Arel::Nodes.build_quoted("$#{dollar_step(key)}") }])
end