Class: ActiveRecord::Refined::AST::JsonContains
- Defined in:
- lib/active_record/refined/ast.rb
Overview
JSON containment: whether the document holds what is given.
Instance Attribute Summary collapse
-
#operand ⇒ Object
readonly
Returns the value of attribute operand.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(operand, value) ⇒ JsonContains
constructor
A new instance of JsonContains.
- #to_arel(table, model) ⇒ Object
Methods inherited from Predicate
Methods inherited from Node
Constructor Details
#initialize(operand, value) ⇒ JsonContains
Returns a new instance of JsonContains.
598 599 600 601 |
# File 'lib/active_record/refined/ast.rb', line 598 def initialize(operand, value) @operand = operand @value = value end |
Instance Attribute Details
#operand ⇒ Object (readonly)
Returns the value of attribute operand.
596 597 598 |
# File 'lib/active_record/refined/ast.rb', line 596 def operand @operand end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
596 597 598 |
# File 'lib/active_record/refined/ast.rb', line 596 def value @value end |
Instance Method Details
#to_arel(table, model) ⇒ Object
603 604 605 606 607 608 609 610 611 612 613 614 615 |
# File 'lib/active_record/refined/ast.rb', line 603 def to_arel(table, model) document = to_arel_operand(operand, table, model) json = Arel::Nodes.build_quoted(JSON.generate(value)) case AST.adapter_family(model) when :postgresql then Arel::Nodes::Contains.new(document, json) when :mysql Arel::Nodes::NamedFunction.new('JSON_CONTAINS', [document, json]) else # Later than the others, since the adapter is only known here. raise NotImplementedError, "contains? has no equivalent on #{model.connection_db_config.adapter}" end end |