diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-01 10:16:34 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-01 11:02:15 -0700 |
commit | 9da52a5e55cc665a539afb45783f84d9f3607282 (patch) | |
tree | c903725b6d82edb17c076188e52a12b593eac9f7 | |
parent | 537fe2bf83fba71a4f75b6ed0ad39935d87045be (diff) | |
download | rails-9da52a5e55cc665a539afb45783f84d9f3607282.tar.gz rails-9da52a5e55cc665a539afb45783f84d9f3607282.tar.bz2 rails-9da52a5e55cc665a539afb45783f84d9f3607282.zip |
push more mutations out of the builder
`configure_dependency` actually defined callbacks, so rename the method
and move it to the appropriate method.
-rw-r--r-- | activerecord/lib/active_record/associations/builder/association.rb | 17 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/builder/has_one.rb | 10 |
2 files changed, 15 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb index b20347a52a..ef397fdb52 100644 --- a/activerecord/lib/active_record/associations/builder/association.rb +++ b/activerecord/lib/active_record/associations/builder/association.rb @@ -53,7 +53,6 @@ module ActiveRecord::Associations::Builder end def build - configure_dependency if options[:dependent] ActiveRecord::Reflection.create(macro, name, scope, options, model) end @@ -70,6 +69,7 @@ module ActiveRecord::Associations::Builder end def define_callbacks(model, reflection) + add_before_destroy_callbacks(model, name) if options[:dependent] Association.extensions.each do |extension| extension.build model, reflection end @@ -103,17 +103,18 @@ module ActiveRecord::Associations::Builder CODE end - def configure_dependency + def valid_dependent_options + raise NotImplementedError + end + + private + + def add_before_destroy_callbacks(model, name) unless valid_dependent_options.include? options[:dependent] raise ArgumentError, "The :dependent option must be one of #{valid_dependent_options}, but is :#{options[:dependent]}" end - n = name - model.before_destroy lambda { |o| o.association(n).handle_dependency } - end - - def valid_dependent_options - raise NotImplementedError + model.before_destroy lambda { |o| o.association(name).handle_dependency } end end end diff --git a/activerecord/lib/active_record/associations/builder/has_one.rb b/activerecord/lib/active_record/associations/builder/has_one.rb index 2406437a07..62d454ce55 100644 --- a/activerecord/lib/active_record/associations/builder/has_one.rb +++ b/activerecord/lib/active_record/associations/builder/has_one.rb @@ -14,12 +14,14 @@ module ActiveRecord::Associations::Builder !options[:through] end - def configure_dependency - super unless options[:through] - end - def valid_dependent_options [:destroy, :delete, :nullify, :restrict_with_error, :restrict_with_exception] end + + private + + def add_before_destroy_callbacks(model, name) + super unless options[:through] + end end end |