Class: ActiveRecord::Refined::AST::JsonSet

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

Overview

Setting a value inside a JSON document, which is what bury does to what dig reads. The document comes back changed rather than being written anywhere; update_all is what writes it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from JsonComparable

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

Methods included from JsonSteps

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

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, path, value) ⇒ JsonSet

Returns a new instance of JsonSet.



1043
1044
1045
1046
1047
# File 'lib/active_record/refined/ast.rb', line 1043

def initialize(operand, path, value)
  @operand = operand
  @path = check_steps(path, "bury")
  @value = value
end

Instance Attribute Details

#operandObject (readonly)

Returns the value of attribute operand.



1041
1042
1043
# File 'lib/active_record/refined/ast.rb', line 1041

def operand
  @operand
end

#pathObject (readonly)

Returns the value of attribute path.



1041
1042
1043
# File 'lib/active_record/refined/ast.rb', line 1041

def path
  @path
end

#valueObject (readonly)

Returns the value of attribute value.



1041
1042
1043
# File 'lib/active_record/refined/ast.rb', line 1041

def value
  @value
end

Instance Method Details

#json_value?Boolean

Always JSON, which is what the comparison guard asks.

Returns:

  • (Boolean)


1050
1051
1052
# File 'lib/active_record/refined/ast.rb', line 1050

def json_value?
  true
end

#to_arel(table, model) ⇒ Object



1054
1055
1056
1057
1058
1059
# File 'lib/active_record/refined/ast.rb', line 1054

def to_arel(table, model)
  Dialect.for(model).json_set(
    to_arel_operand(operand, table, model),
    steps_array, dollar_path, value,
    (to_arel_operand(value, table, model) if expression?), model)
end