Permalink
Browse files

Make validate_options a class method

  • Loading branch information...
1 parent b83f364 commit 3c27b6ee7e34a3ee2e73c3e77f7a13c60b53c3d2 @rafaelfranca rafaelfranca committed Oct 9, 2013
Showing with 3 additions and 3 deletions.
  1. +3 −3 activerecord/lib/active_record/associations/builder/association.rb
@@ -45,7 +45,7 @@ def initialize(name, scope, options, extension)
@scope = scope
@options = options
- validate_options
+ self.class.validate_options(options)
if scope && scope.arity == 0
@scope = proc { instance_exec(&scope) }
@@ -64,8 +64,8 @@ def self.valid_options(options)
VALID_OPTIONS + Association.extensions.flat_map(&:valid_options)
end
- def validate_options
- options.assert_valid_keys(self.class.valid_options(options))
+ def self.validate_options(options)
+ options.assert_valid_keys(valid_options(options))
end
def self.define_extensions(model, name)

2 comments on commit 3c27b6e

Contributor

egilburg replied Oct 10, 2013

For changes such as this, I've wondered what is the rationale for turning an instance method operating on instance data (the options) into a class method to which instance data then has to be passed as an argument? Is it a performance or design consideration?

Thanks!

Owner

rafaelfranca replied Nov 9, 2013

I think you already know the reason but this commit was part of a refactor to remove all the builder instances and decrease the number of allocated objects since all the operations can be done in the class level, so it is a performance consideration.

Please sign in to comment.