Class: Ardm::Query::Expression
- Inherits:
-
Object
- Object
- Ardm::Query::Expression
- Defined in:
- lib/ardm/query/expression.rb
Instance Attribute Summary collapse
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#relation ⇒ Object
readonly
Returns the value of attribute relation.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #arel_target ⇒ Object
-
#initialize(relation, target, value) ⇒ Expression
constructor
A new instance of Expression.
- #resolved_target ⇒ Object
- #scope ⇒ Object
- #to_arel ⇒ Object
Constructor Details
#initialize(relation, target, value) ⇒ Expression
Returns a new instance of Expression.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ardm/query/expression.rb', line 10 def initialize(relation, target, value) @relation = relation @value = value case target when Ardm::Query::Operator @target = target.target @operator = target.operator when Symbol, String @target = target @operator = :eq else raise ArgumentError, "Unknown target #{target.inspect} in Expresion" end end |
Instance Attribute Details
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
4 5 6 |
# File 'lib/ardm/query/expression.rb', line 4 def operator @operator end |
#relation ⇒ Object (readonly)
Returns the value of attribute relation.
4 5 6 |
# File 'lib/ardm/query/expression.rb', line 4 def relation @relation end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
4 5 6 |
# File 'lib/ardm/query/expression.rb', line 4 def target @target end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'lib/ardm/query/expression.rb', line 4 def value @value end |
Class Method Details
.build_scope(relation, target, value) ⇒ Object
6 7 8 |
# File 'lib/ardm/query/expression.rb', line 6 def self.build_scope(relation, target, value) new(relation, target, value).scope end |
Instance Method Details
#arel_target ⇒ Object
30 31 32 |
# File 'lib/ardm/query/expression.rb', line 30 def arel_target arel_table[resolved_target] end |
#resolved_target ⇒ Object
26 27 28 |
# File 'lib/ardm/query/expression.rb', line 26 def resolved_target target_from_association || target end |
#scope ⇒ Object
38 39 40 |
# File 'lib/ardm/query/expression.rb', line 38 def scope relation.where to_arel end |
#to_arel ⇒ Object
34 35 36 |
# File 'lib/ardm/query/expression.rb', line 34 def to_arel arel_target.send(arel_operator, arel_value) end |