diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-12-10 14:12:36 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-12-11 13:20:51 -0200 |
commit | 4c0cddc92c680490f8cafc889a92541ac80dde39 (patch) | |
tree | 4eecd37df22fa5421737195122f4cb6cec5ae246 | |
parent | d0588a2e897d33c6c12e9fc5f8680328d37a26ca (diff) | |
download | rails-4c0cddc92c680490f8cafc889a92541ac80dde39.tar.gz rails-4c0cddc92c680490f8cafc889a92541ac80dde39.tar.bz2 rails-4c0cddc92c680490f8cafc889a92541ac80dde39.zip |
Bring back the valid_options class accessor
It is need in activerecord-deprecated_finders
6 files changed, 14 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb index 37ba1c73b1..f86d975592 100644 --- a/activerecord/lib/active_record/associations/builder/association.rb +++ b/activerecord/lib/active_record/associations/builder/association.rb @@ -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 @@ module ActiveRecord::Associations::Builder 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 @@ module ActiveRecord::Associations::Builder 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) diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb index e8e36e7cd0..7dd8a7deb1 100644 --- a/activerecord/lib/active_record/associations/builder/belongs_to.rb +++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb @@ -4,7 +4,7 @@ module ActiveRecord::Associations::Builder :belongs_to end - def self.valid_options(options) + def self.build_valid_options(options) super + [:foreign_type, :polymorphic, :touch, :counter_cache] end diff --git a/activerecord/lib/active_record/associations/builder/collection_association.rb b/activerecord/lib/active_record/associations/builder/collection_association.rb index 2ff67f904d..b696914883 100644 --- a/activerecord/lib/active_record/associations/builder/collection_association.rb +++ b/activerecord/lib/active_record/associations/builder/collection_association.rb @@ -7,7 +7,7 @@ module ActiveRecord::Associations::Builder 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 diff --git a/activerecord/lib/active_record/associations/builder/has_many.rb b/activerecord/lib/active_record/associations/builder/has_many.rb index 227184cd19..4ec808bc77 100644 --- a/activerecord/lib/active_record/associations/builder/has_many.rb +++ b/activerecord/lib/active_record/associations/builder/has_many.rb @@ -4,7 +4,7 @@ module ActiveRecord::Associations::Builder :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 diff --git a/activerecord/lib/active_record/associations/builder/has_one.rb b/activerecord/lib/active_record/associations/builder/has_one.rb index 064a3c8b51..216d6abec1 100644 --- a/activerecord/lib/active_record/associations/builder/has_one.rb +++ b/activerecord/lib/active_record/associations/builder/has_one.rb @@ -4,7 +4,7 @@ module ActiveRecord::Associations::Builder :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 diff --git a/activerecord/lib/active_record/associations/builder/singular_association.rb b/activerecord/lib/active_record/associations/builder/singular_association.rb index a6e8300642..6a1a0073e6 100644 --- a/activerecord/lib/active_record/associations/builder/singular_association.rb +++ b/activerecord/lib/active_record/associations/builder/singular_association.rb @@ -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 |