Module: DefaultWhere::Not

Included in:
DefaultWhere
Defined in:
lib/default_where/not.rb

Instance Method Summary collapse

Instance Method Details

#filter_not(params) ⇒ Object



24
25
26
27
28
# File 'lib/default_where/not.rb', line 24

def filter_not(params)
  params.select do |k, _|
    k.end_with?('-not')
  end
end

#not_scope(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/default_where/not.rb', line 4

def not_scope(params)
  where_hash = {}

  params.each do |key, value|
    real_key = key.sub(/-not$/, '')

    if column_names.include?(real_key)
      real_key = "#{table_name}.#{real_key}"
    end

    where_hash.merge! real_key => value
  end

  if where_hash.present?
    where.not(where_hash)
  else
    all
  end
end