Module: Scopes::Not::QueryMethods

Defined in:
lib/scopes/not.rb

Instance Method Summary collapse

Instance Method Details

#not(opts, *rest) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/scopes/not.rb', line 8

def not(opts, *rest)
  return self if opts.blank?

  relation = clone
  relation.where_values += build_where(opts, rest).map do |relation|
    # TODO: understanding strict module comparison
    case relation.class.name
    when "Arel::Nodes::Equality"
      Arel::Nodes::NotEqual.new relation.left, relation.right
    when "Arel::Nodes::In"
      Arel::Nodes::NotIn.new relation.left, relation.right
    else
      relation.not
    end
  end
  relation
end