diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-07-19 21:47:09 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-19 21:47:09 -0300 |
commit | ba0433c7c4e9c9a77dc6f99b50fcd89c1916a270 (patch) | |
tree | 5d507315459f940b9159415fdf3ae70418c3f503 /lib/arel/visitors/to_sql.rb | |
parent | 8be8135c0cb87bed6ac661263ee059af49a1b20e (diff) | |
parent | 549c06dc6d1432dcd5994a117716818f96f989af (diff) | |
download | rails-ba0433c7c4e9c9a77dc6f99b50fcd89c1916a270.tar.gz rails-ba0433c7c4e9c9a77dc6f99b50fcd89c1916a270.tar.bz2 rails-ba0433c7c4e9c9a77dc6f99b50fcd89c1916a270.zip |
Merge pull request #328 from vipulnsward/dryup-collectors
DRY up visit_Arel_Nodes_SelectCore
Diffstat (limited to 'lib/arel/visitors/to_sql.rb')
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 46 |
1 files changed, 13 insertions, 33 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 97bade186a..5429bf4ee8 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -243,53 +243,33 @@ module Arel collector = maybe_visit o.set_quantifier, collector - unless o.projections.empty? - collector << SPACE - len = o.projections.length - 1 - o.projections.each_with_index do |x, i| - collector = visit(x, collector) - collector << COMMA unless len == i - end - end + collect_nodes_for o.projections, collector, SPACE if o.source && !o.source.empty? collector << " FROM " collector = visit o.source, collector end - unless o.wheres.empty? - collector << WHERE - len = o.wheres.length - 1 - o.wheres.each_with_index do |x, i| - collector = visit(x, collector) - collector << AND unless len == i - end - end - - unless o.groups.empty? - collector << GROUP_BY - len = o.groups.length - 1 - o.groups.each_with_index do |x, i| - collector = visit(x, collector) - collector << COMMA unless len == i - end - end - + collect_nodes_for o.wheres, collector, WHERE, AND + collect_nodes_for o.groups, collector, GROUP_BY unless o.havings.empty? collector << " HAVING " inject_join o.havings, collector, AND end + collect_nodes_for o.windows, collector, WINDOW + + collector + end - unless o.windows.empty? - collector << WINDOW - len = o.windows.length - 1 - o.windows.each_with_index do |x, i| + def collect_nodes_for nodes, collector, spacer, connector = COMMA + unless nodes.empty? + collector << spacer + len = nodes.length - 1 + nodes.each_with_index do |x, i| collector = visit(x, collector) - collector << COMMA unless len == i + collector << connector unless len == i end end - - collector end def visit_Arel_Nodes_Bin o, collector |