Permalink
Browse files

association builder classes no longer need the model

decouple the builder classes from the model.  Builder objects should be
easier to reuse now.
  • Loading branch information...
1 parent 8ea64bd commit d80a5cce88aca297ca489b90b62e2cc164c238f1 @tenderlove tenderlove committed Aug 1, 2013
@@ -20,21 +20,20 @@ class << self
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 @@ def initialize(model, name, scope, options)
end
end
- def build
+ def build(model)
ActiveRecord::Reflection.create(macro, name, scope, options, model)
end
@@ -14,7 +14,7 @@ def valid_options
attr_reader :block_extension
- def initialize(model, name, scope, options)
+ def initialize(name, scope, options)
super
@mod = nil
if block_given?
@@ -75,7 +75,7 @@ def test_proxy_association_after_scoped
private
def extend!(model)
- builder = ActiveRecord::Associations::Builder::HasMany.new(model, :association_name, nil, {}) { }
+ builder = ActiveRecord::Associations::Builder::HasMany.new(:association_name, nil, {}) { }
builder.define_extensions(model)
end
end

0 comments on commit d80a5cc

Please sign in to comment.