Merge pull request #405 from Kartstig/master

Fixes #82 Case Insensitive Searching
This commit is contained in:
Jon Atack 2014-08-25 14:36:13 +02:00
commit e791a60dbc
2 changed files with 46 additions and 0 deletions

View File

@ -1,11 +1,47 @@
module Arel
module Nodes
%w{
IDoesNotMatch
IMatches
}.each do |name|
const_set name, Class.new(Binary)
end
end
module Predications
def i_matches other
Nodes::IMatches.new self, other
end
def i_does_not_match other
Nodes::IDoesNotMatch.new self, other
end
end
module Visitors
class ToSql < Arel::Visitors::Visitor
def visit_Arel_Nodes_IDoesNotMatch o
"UPPER(#{visit o.left}) NOT LIKE UPPER(#{visit o.right})"
end
def visit_Arel_Nodes_IMatches o
"UPPER(#{visit o.left}) LIKE UPPER(#{visit o.right})"
end
end
class Dot < Arel::Visitors::Visitor
alias :visit_Arel_Nodes_IMatches :binary
alias :visit_Arel_Nodes_IDoesNotMatch :binary
end
class DepthFirst < Visitor
unless method_defined?(:visit_Arel_Nodes_InfixOperation)
alias :visit_Arel_Nodes_InfixOperation :binary
alias :visit_Arel_Nodes_IMatches :binary
alias :visit_Arel_Nodes_IDoesNotMatch :binary
end
end

View File

@ -12,11 +12,21 @@ module Ransack
:formatter => proc { |v| "%#{escape_wildcards(v)}%" }
}
],
['icont', {
:arel_predicate => 'i_matches',
:formatter => proc { |v| "%#{escape_wildcards(v)}%" }
}
],
['not_cont', {
:arel_predicate => 'does_not_match',
:formatter => proc { |v| "%#{escape_wildcards(v)}%" }
}
],
['inot_cont', {
:arel_predicate => 'i_does_not_match',
:formatter => proc { |v| "%#{escape_wildcards(v)}%" }
}
],
['start', {
:arel_predicate => 'matches',
:formatter => proc { |v| "#{escape_wildcards(v)}%" }