Module: BabySqueel::Nodes

Defined in:
lib/baby_squeel/nodes.rb,
lib/baby_squeel/nodes/node.rb,
lib/baby_squeel/nodes/proxy.rb,
lib/baby_squeel/nodes/binary.rb,
lib/baby_squeel/nodes/function.rb,
lib/baby_squeel/nodes/grouping.rb,
lib/baby_squeel/nodes/attribute.rb

Defined Under Namespace

Classes: Attribute, Binary, Function, Grouping, Node, Proxy

Class Method Summary collapse

Class Method Details

.unwrap(node) ⇒ Object

Unwraps a BabySqueel::Proxy before being passed to ActiveRecord.



29
30
31
32
33
34
35
36
37
# File 'lib/baby_squeel/nodes.rb', line 29

def unwrap(node)
  if node.respond_to? :_arel
    unwrap node._arel
  elsif node.is_a? Array
    node.map { |n| unwrap(n) }
  else
    node
  end
end

.wrap(arel) ⇒ Object

Wraps an Arel node in a Proxy so that it can be extended.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/baby_squeel/nodes.rb', line 12

def wrap(arel)
  case arel
  when Arel::Nodes::Grouping
    Grouping.new(arel)
  when Arel::Nodes::Function
    Function.new(arel)
  when Arel::Nodes::Binary
    Binary.new(arel)
  when Arel::Nodes::Node, Arel::Nodes::SqlLiteral
    Node.new(arel)
  else
    arel
  end
end