Class: ActiveRecord::QueryMethods::OrChain

Inherits:
Object
  • Object
show all
Defined in:
lib/by2/ext/active_record.rb

Overview

OrChain objects act as placeholder for queries in which #or does not have any parameter. In this case, #or must be chained with any other relation method to return a new relation. It is intended to allow .or.where() and .or.named_scope.

Instance Method Summary collapse

Constructor Details

#initialize(scope) ⇒ OrChain

Returns a new instance of OrChain.



19
20
21
# File 'lib/by2/ext/active_record.rb', line 19

def initialize(scope)
  @scope = scope
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



23
24
25
26
27
28
# File 'lib/by2/ext/active_record.rb', line 23

def method_missing(method, *args, &block)
  right_relation = @scope.klass.unscoped do
    @scope.klass.send(method, *args, &block)
  end
  @scope.or(right_relation)
end