diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-10-09 20:56:05 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-10-09 20:56:05 -0300 |
commit | d0163e99d9affeccb341e12cc7c50b599f129b5c (patch) | |
tree | 33902eca1430707bc63a04b04d868d7a03027cf5 /activerecord/lib | |
parent | c1cd3424569cf76b0e19e2854ec2829d87ed02bd (diff) | |
download | rails-d0163e99d9affeccb341e12cc7c50b599f129b5c.tar.gz rails-d0163e99d9affeccb341e12cc7c50b599f129b5c.tar.bz2 rails-d0163e99d9affeccb341e12cc7c50b599f129b5c.zip |
Remove builder instances
All the job can be done at class level so we can avoid some object
allocation
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/builder/association.rb | 22 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb | 10 |
2 files changed, 10 insertions, 22 deletions
diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb index 4efd5aa8ba..023afef3b9 100644 --- a/activerecord/lib/active_record/associations/builder/association.rb +++ b/activerecord/lib/active_record/associations/builder/association.rb @@ -18,18 +18,15 @@ module ActiveRecord::Associations::Builder VALID_OPTIONS = [:class_name, :class, :foreign_key, :validate] - attr_reader :name, :scope, :options - def self.build(model, name, scope, options, &block) extension = define_extensions model, name, &block - builder = create_builder model, name, scope, options, extension - reflection = builder.build(model) + reflection = create_reflection model, name, scope, options, extension define_accessors model, reflection define_callbacks model, reflection reflection end - def self.create_builder(model, name, scope, options, extension = nil) + def self.create_reflection(model, name, scope, options, extension = nil) raise ArgumentError, "association names must be a Symbol" unless name.kind_of?(Symbol) if scope.is_a?(Hash) @@ -37,16 +34,11 @@ module ActiveRecord::Associations::Builder scope = nil end - new(name, scope, options, extension) - end - - def initialize(name, scope, options, extension) - @name = name - @options = options + validate_options(options) - self.class.validate_options(options) + scope = build_scope(scope, extension) - @scope = self.class.build_scope(scope, extension) + ActiveRecord::Reflection.create(macro, name, scope, options, model) end def self.build_scope(scope, extension) @@ -67,10 +59,6 @@ module ActiveRecord::Associations::Builder scope end - def build(model) - ActiveRecord::Reflection.create(self.class.macro, name, scope, options, model) - end - def self.macro raise NotImplementedError end diff --git a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb index af596a3a64..1c9c04b044 100644 --- a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb +++ b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb @@ -84,11 +84,11 @@ module ActiveRecord::Associations::Builder middle_name = [lhs_model.name.downcase.pluralize, association_name].join('_').gsub(/::/, '_').to_sym middle_options = middle_options join_model - hm_builder = HasMany.create_builder(lhs_model, - middle_name, - nil, - middle_options) - hm_builder.build lhs_model + + HasMany.create_reflection(lhs_model, + middle_name, + nil, + middle_options) end private |