def initialize_with_deprecated_options(model, name, scope, options)
options = scope if scope.is_a?(Hash)
deprecated_options = options.slice(*DEPRECATED_OPTIONS)
if scope.respond_to?(:call) && !deprecated_options.empty?
raise ArgumentError,
"Invalid mix of scope block and deprecated finder options on " "ActiveRecord association: #{model.name}.#{macro} :#{name}"
end
if scope.is_a?(Hash)
if deprecated_options.empty?
scope = nil
else
ActiveSupport::Deprecation.warn(
"The following options in your #{model.name}.#{macro} :#{name} declaration are deprecated: " "#{deprecated_options.keys.map(&:inspect).join(',')}. Please use a scope block instead. " "For example, the following:\n" "\n" " has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'\n" "\n" "should be rewritten as the following:\n" "\n" " has_many :spam_comments, -> { where spam: true }, class_name: 'Comment'\n"
)
scope = DeprecatedOptionsProc.new(deprecated_options)
options = options.except(*DEPRECATED_OPTIONS)
end
end
initialize_without_deprecated_options(model, name, scope, options)
end