diff --git a/lib/ransack/adapters/active_record/compat.rb b/lib/ransack/adapters/active_record/compat.rb index dbb7d7f..e447404 100644 --- a/lib/ransack/adapters/active_record/compat.rb +++ b/lib/ransack/adapters/active_record/compat.rb @@ -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 diff --git a/lib/ransack/constants.rb b/lib/ransack/constants.rb index 4f61755..0ba488f 100644 --- a/lib/ransack/constants.rb +++ b/lib/ransack/constants.rb @@ -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)}%" }