aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-18 10:43:10 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-18 16:21:10 +0100
commita2e2e73c5ef7c9082810d77c831c50c91011e6d9 (patch)
tree86eb986b1cc598859c3930c52f09e243dce40f9a /railties/lib/rails
parent4c00c65c58055b341b4ca59a38c3c93082049c84 (diff)
downloadrails-a2e2e73c5ef7c9082810d77c831c50c91011e6d9.tar.gz
rails-a2e2e73c5ef7c9082810d77c831c50c91011e6d9.tar.bz2
rails-a2e2e73c5ef7c9082810d77c831c50c91011e6d9.zip
Ensure generators can be invoked by their shortcut and remove attr_reader tasks.
Diffstat (limited to 'railties/lib/rails')
-rw-r--r--railties/lib/rails/generators.rb5
-rw-r--r--railties/lib/rails/generators/base.rb4
-rw-r--r--railties/lib/rails/generators/named_base.rb8
-rw-r--r--railties/lib/rails/generators/resource_helpers.rb10
4 files changed, 19 insertions, 8 deletions
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 3713a38b33..ecd0a1c6ea 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -168,6 +168,8 @@ module Rails
# Rails looks for is the first and last parts of the namespace.
#
def self.find_by_namespace(name, base=nil, context=nil) #:nodoc:
+ base = "rails" unless base || context || name.to_s.include?(?:)
+
# Mount regexps to lookup
regexps = []
regexps << /^#{base}:[\w:]*#{name}$/ if base
@@ -203,8 +205,7 @@ module Rails
# commands.
def self.invoke(namespace, args=ARGV, config={})
names = namespace.to_s.split(':')
-
- if klass = find_by_namespace(names.pop, names.shift || "rails")
+ if klass = find_by_namespace(names.pop, names.shift)
args << "--help" if klass.arguments.any? { |a| a.required? } && args.empty?
klass.start(args, config)
else
diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb
index 26abb46644..9cc342b202 100644
--- a/railties/lib/rails/generators/base.rb
+++ b/railties/lib/rails/generators/base.rb
@@ -324,9 +324,13 @@ module Rails
# added hook is being used.
#
def self.prepare_for_invocation(name, value) #:nodoc:
+ return super unless value.is_a?(String) || value.is_a?(Symbol)
+
if value && constants = self.hooks[name]
value = name if TrueClass === value
Rails::Generators.find_by_namespace(value, *constants)
+ elsif klass = Rails::Generators.find_by_namespace(value)
+ klass
else
super
end
diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb
index 1d4f52286e..3e851bf888 100644
--- a/railties/lib/rails/generators/named_base.rb
+++ b/railties/lib/rails/generators/named_base.rb
@@ -6,10 +6,12 @@ module Rails
class NamedBase < Base
argument :name, :type => :string
- attr_reader :class_name, :singular_name, :plural_name, :table_name,
- :class_path, :file_path, :class_nesting_depth
+ no_tasks {
+ attr_reader :class_name, :singular_name, :plural_name, :table_name,
+ :class_path, :file_path, :class_nesting_depth
- alias :file_name :singular_name
+ alias :file_name :singular_name
+ }
def initialize(args, *options) #:nodoc:
# Unfreeze name in case it's given as a frozen string
diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb
index 99954e2292..7e00a222ed 100644
--- a/railties/lib/rails/generators/resource_helpers.rb
+++ b/railties/lib/rails/generators/resource_helpers.rb
@@ -9,10 +9,14 @@ module Rails
mattr_accessor :skip_warn
def self.included(base) #:nodoc:
- base.send :attr_reader, :controller_name, :controller_class_name, :controller_file_name,
- :controller_class_path, :controller_file_path
+ base.class_eval do
+ class_option :force_plural, :type => :boolean, :desc => "Forces the use of a plural ModelName"
- base.send :class_option, :force_plural, :type => :boolean, :desc => "Forces the use of a plural ModelName"
+ no_tasks {
+ attr_reader :controller_name, :controller_class_name, :controller_file_name,
+ :controller_class_path, :controller_file_path
+ }
+ end
end
# Set controller variables on initialization.