From 08e64913d17f774420698c3dd917c285ebc42e55 Mon Sep 17 00:00:00 2001 From: claudiob Date: Thu, 23 Oct 2014 17:22:17 -0700 Subject: [PATCH] Reuse `maybe_visit` method This commit simply removes duplicated code by reusing the existing `maybe_visit` method. --- lib/arel/visitors/mysql.rb | 7 +------ lib/arel/visitors/to_sql.rb | 15 +++------------ 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/lib/arel/visitors/mysql.rb b/lib/arel/visitors/mysql.rb index 70a37582c2..f989b8ddef 100644 --- a/lib/arel/visitors/mysql.rb +++ b/lib/arel/visitors/mysql.rb @@ -69,12 +69,7 @@ module Arel collector = inject_join o.orders, collector, ', ' end - if o.limit - collector << " " - visit(o.limit, collector) - else - collector - end + maybe_visit o.limit, collector end end diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 7fa3322148..bccf1d4061 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -229,15 +229,9 @@ module Arel def visit_Arel_Nodes_SelectCore o, collector collector << "SELECT" - if o.top - collector << " " - collector = visit o.top, collector - end + maybe_visit o.top, collector - if o.set_quantifier - collector << " " - collector = visit o.set_quantifier, collector - end + maybe_visit o.set_quantifier, collector unless o.projections.empty? collector << SPACE @@ -271,10 +265,7 @@ module Arel end end - if o.having - collector << " " - collector = visit(o.having, collector) - end + maybe_visit o.having, collector unless o.windows.empty? collector << WINDOW