Class: ActiveRecord::Refined::AST::Comparison
- Defined in:
- lib/active_record/refined/ast.rb
Overview
A plain SQL comparison. The value is passed through as it is, so a Range or an Array compares against a PostgreSQL range or array column, the way ActiveRecord's own force_equality? types do.
Constant Summary collapse
- OPERATOR_MAP =
{ :== => :eq, :!= => :not_eq, :> => :gt, :>= => :gteq, :< => :lt, :<= => :lteq }.freeze
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(column, operator, value) ⇒ Comparison
constructor
A new instance of Comparison.
- #to_arel(table, model) ⇒ Object
Methods inherited from Predicate
Methods inherited from Node
Constructor Details
#initialize(column, operator, value) ⇒ Comparison
Returns a new instance of Comparison.
1140 1141 1142 1143 1144 |
# File 'lib/active_record/refined/ast.rb', line 1140 def initialize(column, operator, value) @column = column @operator = operator @value = value end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
1138 1139 1140 |
# File 'lib/active_record/refined/ast.rb', line 1138 def column @column end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
1138 1139 1140 |
# File 'lib/active_record/refined/ast.rb', line 1138 def operator @operator end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
1138 1139 1140 |
# File 'lib/active_record/refined/ast.rb', line 1138 def value @value end |
Instance Method Details
#to_arel(table, model) ⇒ Object
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 |
# File 'lib/active_record/refined/ast.rb', line 1146 def to_arel(table, model) arel_column = to_arel_operand(column, table, model) arel_value = case value when Node then value.to_arel(table, model) when ActiveRecord::Relation then scalar_subquery(value) else value end arel_column.public_send(OPERATOR_MAP.fetch(operator), arel_value) end |