Class: ActiveRecord::Associations::Builder::DeprecatedOptionsProc

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/deprecated_finders/association_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ DeprecatedOptionsProc

Returns a new instance of DeprecatedOptionsProc.



9
10
11
12
13
14
# File 'lib/active_record/deprecated_finders/association_builder.rb', line 9

def initialize(options)
  options[:includes]  = options.delete(:include)    if options[:include]
  options[:where]     = options.delete(:conditions) if options[:conditions]

  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/active_record/deprecated_finders/association_builder.rb', line 7

def options
  @options
end

Instance Method Details

#arityObject



29
30
31
# File 'lib/active_record/deprecated_finders/association_builder.rb', line 29

def arity
  1
end

#to_procObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_record/deprecated_finders/association_builder.rb', line 16

def to_proc
  options = self.options
  proc do |owner|
    if options[:where].respond_to?(:to_proc)
      context = owner || self
      where(context.instance_eval(&options[:where]))
        .merge!(options.except(:where))
    else
      merge(options)
    end
  end
end