Class: Arel::Visitors::ToSql
- Inherits:
-
Object
- Object
- Arel::Visitors::ToSql
- Defined in:
- lib/ransack/adapters/active_record/3.0/compat.rb
Instance Method Summary collapse
- #column_cache ⇒ Object
- #column_for(attr) ⇒ Object
- #visit_Arel_Nodes_And(o) ⇒ Object
- #visit_Arel_Nodes_InfixOperation(o) ⇒ Object
- #visit_Arel_Nodes_NamedFunction(o) ⇒ Object
- #visit_Arel_Nodes_Not(o) ⇒ Object
- #visit_Arel_Nodes_Values(o) ⇒ Object
Instance Method Details
#column_cache ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'lib/ransack/adapters/active_record/3.0/compat.rb', line 120 def column_cache @column_cache ||= Hash.new do |hash, key| hash[key] = Hash[ @engine.connection.columns(key, "#{key} Columns").map do |c| [c.name, c] end ] end end |
#column_for(attr) ⇒ Object
113 114 115 116 117 118 |
# File 'lib/ransack/adapters/active_record/3.0/compat.rb', line 113 def column_for attr name = attr.name.to_s table = attr.relation.table_name column_cache[table][name] end |
#visit_Arel_Nodes_And(o) ⇒ Object
140 141 142 |
# File 'lib/ransack/adapters/active_record/3.0/compat.rb', line 140 def visit_Arel_Nodes_And o o.children.map { |x| visit x }.join ' AND ' end |
#visit_Arel_Nodes_InfixOperation(o) ⇒ Object
130 131 132 |
# File 'lib/ransack/adapters/active_record/3.0/compat.rb', line 130 def visit_Arel_Nodes_InfixOperation o "#{visit o.left} #{o.operator} #{visit o.right}" end |
#visit_Arel_Nodes_NamedFunction(o) ⇒ Object
134 135 136 137 138 |
# File 'lib/ransack/adapters/active_record/3.0/compat.rb', line 134 def visit_Arel_Nodes_NamedFunction o "#{o.name}(#{o.distinct ? 'DISTINCT ' : ''}#{o.expressions.map { |x| visit x }.join(', ')})#{o.alias ? " AS #{visit o.alias}" : ''}" end |
#visit_Arel_Nodes_Not(o) ⇒ Object
144 145 146 |
# File 'lib/ransack/adapters/active_record/3.0/compat.rb', line 144 def visit_Arel_Nodes_Not o "NOT (#{visit o.expr})" end |
#visit_Arel_Nodes_Values(o) ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/ransack/adapters/active_record/3.0/compat.rb', line 148 def visit_Arel_Nodes_Values o "VALUES (#{o.expressions.zip(o.columns).map { |value, attr| if Nodes::SqlLiteral === value visit_Arel_Nodes_SqlLiteral value else quote(value, attr && column_for(attr)) end }.join ', '})" end |