Class: ActiveRecord::Refined::AST::JsonSet
- Includes:
- 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
-
#operand ⇒ Object
readonly
Returns the value of attribute operand.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(operand, path, value) ⇒ JsonSet
constructor
A new instance of JsonSet.
- #to_arel(table, model) ⇒ Object
Methods included from JsonSteps
#check_steps, #dollar_path, #escape_step, #steps_array
Methods included from Predications
#!=, #!~, #<, #<=, #==, #=~, #>, #>=, #between?, #bury, #casecmp?, #contains?, #dig, #dig_json, #distinct_from?, #end_with?, #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
Constructor Details
#initialize(operand, path, value) ⇒ JsonSet
Returns a new instance of JsonSet.
547 548 549 550 551 |
# File 'lib/active_record/refined/ast.rb', line 547 def initialize(operand, path, value) @operand = operand @path = check_steps(path, 'bury') @value = value end |
Instance Attribute Details
#operand ⇒ Object (readonly)
Returns the value of attribute operand.
545 546 547 |
# File 'lib/active_record/refined/ast.rb', line 545 def operand @operand end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
545 546 547 |
# File 'lib/active_record/refined/ast.rb', line 545 def path @path end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
545 546 547 |
# File 'lib/active_record/refined/ast.rb', line 545 def value @value end |
Instance Method Details
#to_arel(table, model) ⇒ Object
553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'lib/active_record/refined/ast.rb', line 553 def to_arel(table, model) document = to_arel_operand(operand, table, model) if AST.adapter_family(model) == :postgresql Arel::Nodes::NamedFunction.new( 'jsonb_set', [document, Arel::Nodes.build_quoted(steps_array), postgresql_value(table, model)]) else Arel::Nodes::NamedFunction.new( 'JSON_SET', [document, Arel::Nodes.build_quoted(dollar_path), other_value(table, model)]) end end |