diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-01 11:43:11 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-01 11:43:52 -0700 |
commit | d80a5cce88aca297ca489b90b62e2cc164c238f1 (patch) | |
tree | 81a510720377e12ddcf8751737f2ed854b07c803 /activerecord/lib/active_record/associations | |
parent | 8ea64bd0fce854a4bb85bf67c983d30358c8cd39 (diff) | |
download | rails-d80a5cce88aca297ca489b90b62e2cc164c238f1.tar.gz rails-d80a5cce88aca297ca489b90b62e2cc164c238f1.tar.bz2 rails-d80a5cce88aca297ca489b90b62e2cc164c238f1.zip |
association builder classes no longer need the model
decouple the builder classes from the model. Builder objects should be
easier to reuse now.
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/builder/association.rb | 11 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/builder/collection_association.rb | 2 |
2 files changed, 6 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb index 84c340db26..926b6d21cd 100644 --- a/activerecord/lib/active_record/associations/builder/association.rb +++ b/activerecord/lib/active_record/associations/builder/association.rb @@ -20,21 +20,20 @@ module ActiveRecord::Associations::Builder self.valid_options = [:class_name, :foreign_key, :validate] self.extensions = [] - attr_reader :model, :name, :scope, :options + attr_reader :name, :scope, :options def self.build(model, name, scope, options, &block) raise ArgumentError, "association names must be a Symbol" unless name.kind_of?(Symbol) - builder = new(model, name, scope, options, &block) - reflection = builder.build + builder = new(name, scope, options, &block) + reflection = builder.build(model) builder.define_accessors model builder.define_callbacks model, reflection builder.define_extensions model reflection end - def initialize(model, name, scope, options) - @model = model + def initialize(name, scope, options) @name = name if scope.is_a?(Hash) @@ -53,7 +52,7 @@ module ActiveRecord::Associations::Builder end end - def build + def build(model) ActiveRecord::Reflection.create(macro, name, scope, options, model) end diff --git a/activerecord/lib/active_record/associations/builder/collection_association.rb b/activerecord/lib/active_record/associations/builder/collection_association.rb index fd40b320e3..bc63e18955 100644 --- a/activerecord/lib/active_record/associations/builder/collection_association.rb +++ b/activerecord/lib/active_record/associations/builder/collection_association.rb @@ -14,7 +14,7 @@ module ActiveRecord::Associations::Builder attr_reader :block_extension - def initialize(model, name, scope, options) + def initialize(name, scope, options) super @mod = nil if block_given? |