Sha256: 97add67f13a48d535d753e420975b8b02edefe76895d65e6e7634712f6c0a7b9

Contents?: true

Size: 683 Bytes

Versions: 16

Compression:

Stored size: 683 Bytes

Contents

module Trax
  module Model
    module Matchable
      extend ::ActiveSupport::Concern

      included do
        ::String.class_eval do
          def to_matchable
            "%#{self.strip}%"
          end
        end
      end

      module ClassMethods
        def matching(args = {})
          matches = args.inject(self.all) do |scope, (key, value)|
            node = key.is_a?(Symbol) ? self.arel_table[key] : key

            values = [value]

            match_values = values.flatten.compact.uniq.map!(&:to_matchable)
            scope = scope.where(node.matches_any(match_values))
            scope
          end

          matches
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
trax_model-0.0.98 lib/trax/model/matchable.rb
trax_model-0.0.97 lib/trax/model/matchable.rb
trax_model-0.0.96 lib/trax/model/matchable.rb
trax_model-0.0.95 lib/trax/model/matchable.rb
trax_model-0.0.93 lib/trax/model/matchable.rb
trax_model-0.0.92 lib/trax/model/matchable.rb
trax_model-0.0.91 lib/trax/model/matchable.rb
trax_model-0.0.9 lib/trax/model/matchable.rb
trax_model-0.0.8 lib/trax/model/matchable.rb
trax_model-0.0.7 lib/trax/model/matchable.rb
trax_model-0.0.6 lib/trax/model/matchable.rb
trax_model-0.0.5 lib/trax/model/matchable.rb
trax_model-0.0.4 lib/trax/model/matchable.rb
trax_model-0.0.3 lib/trax/model/matchable.rb
trax_model-0.0.2 lib/trax/model/matchable.rb
trax_model-0.0.1 lib/trax/model/matchable.rb