aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-04-10 17:36:57 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-04-10 17:36:57 +0000
commit9a97cb25eb37c2cf9eb3ab4b0c4350db0bf66678 (patch)
tree3c2ff4fe4836e2d5b8178bdcd582449dfa801c18 /railties
parenta677da209b16f43198b3485dda89dce862fb9bfb (diff)
downloadrails-9a97cb25eb37c2cf9eb3ab4b0c4350db0bf66678.tar.gz
rails-9a97cb25eb37c2cf9eb3ab4b0c4350db0bf66678.tar.bz2
rails-9a97cb25eb37c2cf9eb3ab4b0c4350db0bf66678.zip
Added lazy typing for generate, such that ./script/generate cn == ./script/generate controller and the likes #1051 [k@v2studio.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1137 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/rails_generator/lookup.rb12
2 files changed, 11 insertions, 3 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 62eb3568ad..4cb507759f 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added lazy typing for generate, such that ./script/generate cn == ./script/generate controller and the likes #1051 [k@v2studio.com]
+
* Fixed that ownership is brought over in pg_dump during tests for PostgreSQL #1060 [pburleson@gmail.com]
diff --git a/railties/lib/rails_generator/lookup.rb b/railties/lib/rails_generator/lookup.rb
index 00b78ce645..538e0f55ea 100644
--- a/railties/lib/rails_generator/lookup.rb
+++ b/railties/lib/rails_generator/lookup.rb
@@ -109,9 +109,15 @@ module Rails
def lookup(generator_name)
@found ||= {}
generator_name = generator_name.to_s.downcase
- @found[generator_name] ||= cache.find { |spec|
- spec.name == generator_name
- } or raise GeneratorError, "Couldn't find '#{generator_name}' generator"
+ @found[generator_name] ||= cache.find { |spec| spec.name == generator_name }
+ unless @found[generator_name]
+ chars = generator_name.scan(/./).map{|c|"#{c}.*?"}
+ rx = /^#{chars}$/
+ gns = cache.select{|spec| spec.name =~ rx }
+ @found[generator_name] ||= gns.first if gns.length == 1
+ raise GeneratorError, "Pattern '#{generator_name}' matches more than one generator: #{gns.map{|sp|sp.name}.join(', ')}" if gns.length > 1
+ end
+ @found[generator_name] or raise GeneratorError, "Couldn't find '#{generator_name}' generator"
end
# Convenience method to lookup and instantiate a generator.