Skip to content

Commit

Permalink
Make validate_options a class method
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Oct 9, 2013
1 parent b83f364 commit 3c27b6e
Showing 1 changed file with 3 additions and 3 deletions.
Expand Up @@ -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) }
Expand All @@ -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)
Expand Down

2 comments on commit 3c27b6e

@egilburg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@rafaelfranca
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.