Module: Trax::Model::Matchable::ClassMethods

Defined in:
lib/trax/model/matchable.rb

Instance Method Summary collapse

Instance Method Details

#matching(args = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/trax/model/matchable.rb', line 7

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

    values = [value]
    values.flat_compact_uniq!
    values.map!(&:to_matchable)

    scope = scope.where(node.matches_any(values))
    scope
  end

  matches
end