Permalink
Browse files

Bring back the valid_options class accessor

It is need in activerecord-deprecated_finders
  • Loading branch information...
1 parent d0588a2 commit 4c0cddc92c680490f8cafc889a92541ac80dde39 @rafaelfranca rafaelfranca committed Dec 10, 2013
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/module/attribute_accessors'
+
# This is the parent Association class which defines the variables
# used by all associations.
#
@@ -16,7 +18,10 @@ class << self
end
self.extensions = []
- VALID_OPTIONS = [:class_name, :class, :foreign_key, :validate]
+ # TODO: This class accessor is needed to make activerecord-deprecated_finders work.
+ # We can move it to a constant in 5.0.
+ cattr_accessor :valid_options, instance_accessor: false
+ self.valid_options = [:class_name, :class, :foreign_key, :validate]
def self.build(model, name, scope, options, &block)
extension = define_extensions model, name, &block
@@ -63,12 +68,12 @@ def self.macro
raise NotImplementedError
end
- def self.valid_options(options)
- VALID_OPTIONS + Association.extensions.flat_map(&:valid_options)
+ def self.build_valid_options(options)
+ self.valid_options + Association.extensions.flat_map(&:valid_options)
end
def self.validate_options(options)
- options.assert_valid_keys(valid_options(options))
+ options.assert_valid_keys(build_valid_options(options))
end
def self.define_extensions(model, name)
@@ -4,7 +4,7 @@ def self.macro
:belongs_to
end
- def self.valid_options(options)
+ def self.build_valid_options(options)
super + [:foreign_type, :polymorphic, :touch, :counter_cache]
end
@@ -7,7 +7,7 @@ class CollectionAssociation < Association #:nodoc:
CALLBACKS = [:before_add, :after_add, :before_remove, :after_remove]
- def self.valid_options(options)
+ def self.build_valid_options(options)
super + [:table_name, :before_add,
:after_add, :before_remove, :after_remove, :extend]
end
@@ -4,7 +4,7 @@ def self.macro
:has_many
end
- def self.valid_options(options)
+ def self.build_valid_options(options)
super + [:primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache]
end
@@ -4,7 +4,7 @@ def self.macro
:has_one
end
- def self.valid_options(options)
+ def self.build_valid_options(options)
valid = super + [:order, :as]
valid += [:through, :source, :source_type] if options[:through]
valid
@@ -2,7 +2,7 @@
module ActiveRecord::Associations::Builder
class SingularAssociation < Association #:nodoc:
- def self.valid_options(options)
+ def self.build_valid_options(options)
super + [:remote, :dependent, :primary_key, :inverse_of]
end

0 comments on commit 4c0cddc

Please sign in to comment.