Class: ActiveRecord::Refined::AST::JsonSet
- 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
-
#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
-
#as_json ⇒ Object
Always JSON, which is what the comparison guard asks.
-
#initialize(operand, path, value) ⇒ JsonSet
constructor
A new instance of JsonSet.
- #to_arel(table, model) ⇒ Object
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?, #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.
667 668 669 670 671 |
# File 'lib/active_record/refined/ast.rb', line 667 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.
665 666 667 |
# File 'lib/active_record/refined/ast.rb', line 665 def operand @operand end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
665 666 667 |
# File 'lib/active_record/refined/ast.rb', line 665 def path @path end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
665 666 667 |
# File 'lib/active_record/refined/ast.rb', line 665 def value @value end |
Instance Method Details
#as_json ⇒ Object
Always JSON, which is what the comparison guard asks.
674 675 676 |
# File 'lib/active_record/refined/ast.rb', line 674 def as_json true end |
#to_arel(table, model) ⇒ Object
678 679 680 681 682 683 684 685 686 687 688 689 |
# File 'lib/active_record/refined/ast.rb', line 678 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 |