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
123 124 125 126 127 128 129 130 131 |
# File 'lib/ransack/adapters/active_record/3.0/compat.rb', line 123 def column_cache @column_cache ||= Hash.new do |hash, key| hash[key] = Hash[ @engine.connection .columns(key, "#{key} Columns") .map { |c| [c.name, c] } ] end end |
#column_for(attr) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/ransack/adapters/active_record/3.0/compat.rb', line 116 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
149 150 151 |
# File 'lib/ransack/adapters/active_record/3.0/compat.rb', line 149 def visit_Arel_Nodes_And o o.children.map { |x| visit x }.join(Ransack::Constants::SPACED_AND) end |
#visit_Arel_Nodes_InfixOperation(o) ⇒ Object
133 134 135 |
# File 'lib/ransack/adapters/active_record/3.0/compat.rb', line 133 def visit_Arel_Nodes_InfixOperation o "#{visit o.left} #{o.operator} #{visit o.right}" end |
#visit_Arel_Nodes_NamedFunction(o) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/ransack/adapters/active_record/3.0/compat.rb', line 137 def visit_Arel_Nodes_NamedFunction o "#{ o.name }(#{ o.distinct ? Ransack::Constants::DISTINCT : Ransack::Constants::EMPTY }#{ o.expressions.map { |x| visit x }.join(Ransack::Constants::COMMA_SPACE) })#{ o.alias ? " AS #{visit o.alias}" : Ransack::Constants::EMPTY }" end |
#visit_Arel_Nodes_Not(o) ⇒ Object
153 154 155 |
# File 'lib/ransack/adapters/active_record/3.0/compat.rb', line 153 def visit_Arel_Nodes_Not o "NOT (#{visit o.expr})" end |
#visit_Arel_Nodes_Values(o) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/ransack/adapters/active_record/3.0/compat.rb', line 157 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(Ransack::Constants::COMMA_SPACE) })" end |