Refactor inject
This commit is contained in:
parent
21aa9d7928
commit
759ea63a8e
|
@ -3,13 +3,7 @@ if Arel::Nodes::And < Arel::Nodes::Binary
|
||||||
class Ransack::Visitor
|
class Ransack::Visitor
|
||||||
def visit_Ransack_Nodes_And(object)
|
def visit_Ransack_Nodes_And(object)
|
||||||
nodes = object.values.map { |o| accept(o) }.compact
|
nodes = object.values.map { |o| accept(o) }.compact
|
||||||
return nil unless nodes.size > 0
|
|
||||||
|
|
||||||
if nodes.size > 1
|
|
||||||
nodes.inject(&:and)
|
nodes.inject(&:and)
|
||||||
else
|
|
||||||
nodes.first
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,15 +10,10 @@ module Ransack
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
if predicates.size > 1
|
if predicates.size > 1 && combinator == 'and'
|
||||||
case combinator
|
|
||||||
when 'and'
|
|
||||||
Arel::Nodes::Grouping.new(Arel::Nodes::And.new(predicates))
|
Arel::Nodes::Grouping.new(Arel::Nodes::And.new(predicates))
|
||||||
when 'or'
|
|
||||||
predicates.inject(&:or)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
predicates.first
|
predicates.inject(&:or)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,7 @@ module Ransack
|
||||||
class Visitor
|
class Visitor
|
||||||
def visit_and(object)
|
def visit_and(object)
|
||||||
nodes = object.values.map { |o| accept(o) }.compact
|
nodes = object.values.map { |o| accept(o) }.compact
|
||||||
return nil unless nodes.size > 0
|
|
||||||
|
|
||||||
if nodes.size > 1
|
|
||||||
nodes.inject(&:and)
|
nodes.inject(&:and)
|
||||||
else
|
|
||||||
nodes.first
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def quoted?(object)
|
def quoted?(object)
|
||||||
|
|
|
@ -31,13 +31,7 @@ module Ransack
|
||||||
|
|
||||||
def visit_or(object)
|
def visit_or(object)
|
||||||
nodes = object.values.map { |o| accept(o) }.compact
|
nodes = object.values.map { |o| accept(o) }.compact
|
||||||
return nil unless nodes.size > 0
|
|
||||||
|
|
||||||
if nodes.size > 1
|
|
||||||
nodes.inject(&:or)
|
nodes.inject(&:or)
|
||||||
else
|
|
||||||
nodes.first
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def quoted?(object)
|
def quoted?(object)
|
||||||
|
|
Loading…
Reference in New Issue