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.
1010 1011 1012 1013 |
# File 'lib/active_record/refined/ast.rb', line 1010 def initialize(operand, value) @operand = operand @value = value end |
Instance Attribute Details
#operand ⇒ Object (readonly)
Returns the value of attribute operand.
1008 1009 1010 |
# File 'lib/active_record/refined/ast.rb', line 1008 def operand @operand end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
1008 1009 1010 |
# File 'lib/active_record/refined/ast.rb', line 1008 def value @value end |
Instance Method Details
#to_arel(table, model) ⇒ Object
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 |
# File 'lib/active_record/refined/ast.rb', line 1015 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 |