Permalink
Browse files

push more mutations out of the builder

`configure_dependency` actually defined callbacks, so rename the method
and move it to the appropriate method.
  • Loading branch information...
1 parent 537fe2b commit 9da52a5e55cc665a539afb45783f84d9f3607282 @tenderlove tenderlove committed Aug 1, 2013
@@ -53,7 +53,6 @@ def initialize(model, name, scope, options)
end
def build
- configure_dependency if options[:dependent]
ActiveRecord::Reflection.create(macro, name, scope, options, model)
end
@@ -70,6 +69,7 @@ def validate_options
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 @@ def #{name}=(value)
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
@@ -14,12 +14,14 @@ def constructable?
!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

0 comments on commit 9da52a5

Please sign in to comment.