Browse files

avoid using alias in generators

Ruby's alias produces public methods, causing a spurious Thor task
to be created.  For example, this is the reason MigrationGenerator
currently has two tasks:

    > ActiveRecord::Generators::MigrationGenerator.all_tasks.keys
    => ["singular_name", "create_migration_file"]

singular_name was meant to be an attribute, not a task.  Because it's
public, it gets called as a task every time the generator is invoked.

The fix is to ensure all generator methods have the correct
visibility.
  • Loading branch information...
1 parent 9df2584 commit 21e4113e9d7ffa869c405c047ec2fa9fac11e8a1 @bronson bronson committed Jan 26, 2013
Showing with 4 additions and 1 deletion.
  1. +4 −1 railties/lib/rails/generators/named_base.rb
View
5 railties/lib/rails/generators/named_base.rb
@@ -28,7 +28,10 @@ def template(source, *args, &block)
protected
attr_reader :file_name
- alias :singular_name :file_name
+
+ def singular_name
+ file_name
+ end
# Wrap block with namespace of current application
# if namespace exists and is not skipped

0 comments on commit 21e4113

Please sign in to comment.