Class: BabySqueel::Nodes::Attribute

Inherits:
Node
  • Object
show all
Defined in:
lib/baby_squeel/nodes/attribute.rb

Instance Method Summary collapse

Methods included from Operators::ArelAliasing

#arel_alias

Methods included from Operators::Generic

#op

Methods inherited from Proxy

const_missing, #inspect, #respond_to?

Constructor Details

#initialize(parent, name) ⇒ Attribute

Returns a new instance of Attribute.



6
7
8
9
10
# File 'lib/baby_squeel/nodes/attribute.rb', line 6

def initialize(parent, name)
  @parent = parent
  @name = name.to_s
  super(parent._table[@name])
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BabySqueel::Nodes::Proxy

Instance Method Details

#_arelObject



28
29
30
31
32
33
34
# File 'lib/baby_squeel/nodes/attribute.rb', line 28

def _arel
  if @parent.kind_of?(BabySqueel::Association) && !@parent.alias?
    @parent.find_alias[@name]
  else
    super
  end
end

#in(rel) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/baby_squeel/nodes/attribute.rb', line 12

def in(rel)
  if rel.is_a? ::ActiveRecord::Relation
    Nodes.wrap ::Arel::Nodes::In.new(self, sanitize_relation(rel))
  else
    super
  end
end

#not_in(rel) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/baby_squeel/nodes/attribute.rb', line 20

def not_in(rel)
  if rel.is_a? ::ActiveRecord::Relation
    Nodes.wrap ::Arel::Nodes::NotIn.new(self, sanitize_relation(rel))
  else
    super
  end
end