Module: ActiveRecord::WhereAnyOfMixin

Defined in:
lib/active_record/where-any-of-mixin.rb,
lib/active_record/where-any-of-mixin-rails-5.rb

Instance Method Summary collapse

Instance Method Details

#__convert_string_wheres(wheres) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/active_record/where-any-of-mixin.rb', line 21

def __convert_string_wheres(wheres)
  wheres.map do |w|
    if w.is_a?(Arel::Nodes::Equality)
      w
    else
      w = Arel.sql(w) if String === w
      Arel::Nodes::Grouping.new(w)
    end
  end
end

#where_any_of(*conditions) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/active_record/where-any-of-mixin.rb', line 5

def where_any_of(*conditions)
  # Takes any number of scopes and OR them together
  # into a new scope which can be combined with other scopes
  bind_values = []
  conditions = conditions.map do |c|
    if c.is_a? Symbol or c.is_a? String
      c = self.unscoped.send(c)
    end
    bind_values.concat(c.bind_values)
    __convert_string_wheres(c.where_values).reduce(:and)
  end
  s = where(conditions.reduce(:or))
  s.bind_values += bind_values if bind_values.present?
  s
end