Method: Trax::Model::Matchable::ClassMethods#matching

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

#matching(args = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/trax/model/matchable.rb', line 15

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