Class: Ardm::Query::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/ardm/query/expression.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#operatorObject (readonly)

Returns the value of attribute operator.



4
5
6
# File 'lib/ardm/query/expression.rb', line 4

def operator
  @operator
end

#relationObject (readonly)

Returns the value of attribute relation.



4
5
6
# File 'lib/ardm/query/expression.rb', line 4

def relation
  @relation
end

#targetObject (readonly)

Returns the value of attribute target.



4
5
6
# File 'lib/ardm/query/expression.rb', line 4

def target
  @target
end

#valueObject (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_targetObject



30
31
32
# File 'lib/ardm/query/expression.rb', line 30

def arel_target
  arel_table[resolved_target]
end

#resolved_targetObject



26
27
28
# File 'lib/ardm/query/expression.rb', line 26

def resolved_target
  target_from_association || target
end

#scopeObject



38
39
40
# File 'lib/ardm/query/expression.rb', line 38

def scope
  relation.where to_arel
end

#to_arelObject



34
35
36
# File 'lib/ardm/query/expression.rb', line 34

def to_arel
  arel_target.send(arel_operator, arel_value)
end