Skip to content

Commit

Permalink
Follow up to #486: Extract to private methods, document
Browse files Browse the repository at this point in the history
the reason behind this patch and add a FIX ME comment to encourage PRs
to improve it.
  • Loading branch information
jonatack committed Jan 4, 2015
1 parent b7f1401 commit c16ab7a
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions lib/ransack/adapters/active_record/ransack/nodes/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,30 @@ def arel_predicate
predicates.inject(&:or)
end
else
predicates.first.right[0] = predicates.first.right[0].val if defined?(Arel::Nodes::Casted) && predicates.first.class == Arel::Nodes::In && predicates.first.right.is_a?(Array) && predicates.first.right[0].class == Arel::Nodes::Casted
predicates.first
return_predicate(predicates.first)
end
end

end # Condition
private

# FIXME: Improve this edge case patch for Arel >= 6.0 (Rails >= 4.2)
# that adds several conditionals to handle changing Arel API.
# Related to Ransack github issue #472 and pull request #486.
#
def return_predicate(predicate)
if casted_array_with_in_predicate?(predicate)
predicate.right[0] = predicate.right[0].val
end
predicate
end
#
def casted_array_with_in_predicate?(predicate)
return unless defined?(Arel::Nodes::Casted)
predicate.class == Arel::Nodes::In &&
predicate.right.is_a?(Array) &&
predicate.right[0].class == Arel::Nodes::Casted
end

end
end
end

0 comments on commit c16ab7a

Please sign in to comment.