Sha256: 943ea7af0c578f2fe783ee272949860e0e1b61c3d67f8476f147c185130cfcc2

Contents?: true

Size: 874 Bytes

Versions: 2

Compression:

Stored size: 874 Bytes

Contents

module Wherex
  module Visitor

    def self.included base
      base.class_eval do
        alias_method_chain :visit_Arel_Nodes_Equality, :wherex
        alias_method_chain :visit_Arel_Nodes_NotEqual, :wherex
      end
    end

    def visit_Arel_Nodes_Equality_with_wherex o
      right = o.right
      if right.present? and right.is_a? Regexp
        ::ActiveRecord::Base.connection.regexp visit(o.left), visit(right)
      else
        visit_Arel_Nodes_Equality_without_wherex o
      end
    end

    def visit_Arel_Nodes_NotEqual_with_wherex o
      right = o.right
      if right.present? and right.is_a? Regexp
        ::ActiveRecord::Base.connection.regexp_not visit(o.left), visit(right)
      else
        visit_Arel_Nodes_NotEqual_without_wherex o
      end
    end

    def visit_Regexp o; ::ActiveRecord::Base.connection.regexp_quote(o.source) end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wherex-1.0.8 lib/wherex/visitor.rb
wherex-1.0.7 lib/wherex/visitor.rb