Module: Switchman::Arel::Visitors::ToSql

Defined in:
lib/switchman/arel.rb

Instance Method Summary collapse

Instance Method Details

#quote_local_table_name(name) ⇒ Object

rubocop:enable Naming/MethodName rubocop:enable Naming/MethodParameterName



53
54
55
56
57
# File 'lib/switchman/arel.rb', line 53

def quote_local_table_name(name)
  return name if ::Arel::Nodes::SqlLiteral === name

  @connection.quote_local_table_name(name)
end

#visit_Arel_Attributes_Attribute(o, collector) ⇒ Object



22
23
24
25
# File 'lib/switchman/arel.rb', line 22

def visit_Arel_Attributes_Attribute(o, collector)
  join_name = o.relation.table_alias || o.relation.name
  collector << quote_local_table_name(join_name) << '.' << quote_column_name(o.name)
end

#visit_Arel_Nodes_HomogeneousIn(o, collector) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/switchman/arel.rb', line 27

def visit_Arel_Nodes_HomogeneousIn(o, collector)
  collector.preparable = false

  collector << quote_local_table_name(o.table_name) << '.' << quote_column_name(o.column_name)

  collector << if o.type == :in
                 ' IN ('
               else
                 ' NOT IN ('
               end

  values = o.casted_values

  if values.empty?
    collector << @connection.quote(nil)
  else
    collector.add_binds(values, o.proc_for_binds, &bind_block)
  end

  collector << ')'
  collector
end

#visit_Arel_Nodes_TableAlias(o, collector) ⇒ Object

rubocop:disable Naming/MethodName rubocop:disable Naming/MethodParameterName



16
17
18
19
20
# File 'lib/switchman/arel.rb', line 16

def visit_Arel_Nodes_TableAlias(o, collector)
  collector = visit o.relation, collector
  collector << ' '
  collector << quote_local_table_name(o.name)
end