Skip to content

Commit 4d1f4ed

Browse files
committed
Refactor code to make it more clear
Extract the conditional to a method that explains what it needs to do. Also avoid calling `present?`.
1 parent 1083a9c commit 4d1f4ed

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

activerecord/lib/arel/visitors/to_sql.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ def infix_value_with_paren(o, collector, value, suppress_parens = false)
979979

980980
# Used by some visitors to enclose select queries in parentheses
981981
def grouping_parentheses(o, collector, always_wrap_selects = true)
982-
if o.is_a?(Nodes::SelectStatement) && (always_wrap_selects || o.orders.present? || o.limit.present? || o.offset.present?)
982+
if o.is_a?(Nodes::SelectStatement) && (always_wrap_selects || require_parentheses?(o))
983983
collector << "("
984984
visit o, collector
985985
collector << ")"
@@ -989,6 +989,10 @@ def grouping_parentheses(o, collector, always_wrap_selects = true)
989989
end
990990
end
991991

992+
def require_parentheses?(o)
993+
!o.orders.empty? || o.limit || o.offset
994+
end
995+
992996
def aggregate(name, o, collector)
993997
collector << "#{name}("
994998
if o.distinct

0 commit comments

Comments
 (0)