From 21e4113e9d7ffa869c405c047ec2fa9fac11e8a1 Mon Sep 17 00:00:00 2001 From: Scott Bronson Date: Fri, 25 Jan 2013 20:27:33 -0800 Subject: avoid using alias in generators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- railties/lib/rails/generators/named_base.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 9965db98de..8f5118c3b0 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -28,7 +28,10 @@ module Rails 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 -- cgit v1.2.3