Sha256: 01e3c7270757fd7f35682e5ff87226d2b1fe8d2a726c10f3bda7c07846bee639

Contents?: true

Size: 921 Bytes

Versions: 5

Compression:

Stored size: 921 Bytes

Contents

module ActiveRecordSeek
  module Operators
    class MatchesBaseOperator < BaseOperator

    end

    {
      like:         :matches,
      like_all:     :matches_all,
      like_any:     :matches_any,
      not_like:     :does_not_match,
      not_like_all: :does_not_match_all,
      not_like_any: :does_not_match_any,
    }.each do |seek_operator, arel_operator|
      operator_class = Class.new(MatchesBaseOperator) do
        define_method(:arel_operation) do
          operation = arel_column.send(arel_operator, arel_value)
          # switch to LIKE operator
          operation.each do |operation_part|
            if operation_part.class.in?([Arel::Nodes::Matches, Arel::Nodes::DoesNotMatch])
              operation_part.case_sensitive = true
            end
          end
          operation
        end
      end

      const_set("#{seek_operator.to_s.camelcase}Operator", operator_class)
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
active_record_seek-0.0.5 lib/active_record_seek/operators/matches_base_operator.rb
active_record_seek-0.0.4 lib/active_record_seek/operators/matches_base_operator.rb
active_record_seek-0.0.3 lib/active_record_seek/operators/matches_base_operator.rb
active_record_seek-0.0.2 lib/active_record_seek/operators/matches_base_operator.rb
active_record_seek-0.0.1 lib/active_record_seek/operators/matches_base_operator.rb