Module: DefaultWhere::Or

Defined in:
lib/default_where/or.rb

Instance Method Summary collapse

Instance Method Details

#filter_or(params) ⇒ Object



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

def filter_or(params)
  params.select do |k, _|
    k.include?('-or-')
  end
end

#or_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/or.rb', line 4

def or_scope(params)
  where_hash = {}

  params.each do |key, value|
    real_key = key.split('-or-')

    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