Class: ActiveRecordOr::Or

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_or.rb

Instance Method Summary collapse

Constructor Details

#initialize(left) ⇒ Or

Returns a new instance of Or.



5
6
7
# File 'lib/active_record_or.rb', line 5

def initialize(left)
  @left = left
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/active_record_or.rb', line 9

def method_missing(method, *args, &block)
  last_left_constraint = @left.constraints.last
  return @left.send(method, *args, &block) unless last_left_constraint

  raw_right = @left.unscoped.send(method, *args, &block)

  or_based_constraints = last_left_constraint.or(raw_right.constraints.last)
  right = @left.send(method, *args, &block)
  right.where_values = [or_based_constraints]
  right
end