aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/generators/resource_helpers.rb
diff options
context:
space:
mode:
authorJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-25 13:13:29 +0100
committerJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-25 13:20:32 +0100
commit9cb3ca1d29eb770c1a7adac3798666847fceee2b (patch)
tree70aeb2f12e00d98c13d7f55bdd9d445d4223fcfd /railties/lib/rails/generators/resource_helpers.rb
parentad8f5d4106c77ed1d054bf3b29bec94df557a7cd (diff)
downloadrails-9cb3ca1d29eb770c1a7adac3798666847fceee2b.tar.gz
rails-9cb3ca1d29eb770c1a7adac3798666847fceee2b.tar.bz2
rails-9cb3ca1d29eb770c1a7adac3798666847fceee2b.zip
Change mailer generator templates and refactor the whole naming schema.
Diffstat (limited to 'railties/lib/rails/generators/resource_helpers.rb')
-rw-r--r--railties/lib/rails/generators/resource_helpers.rb43
1 files changed, 23 insertions, 20 deletions
diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb
index 7e00a222ed..3a98a8f9c1 100644
--- a/railties/lib/rails/generators/resource_helpers.rb
+++ b/railties/lib/rails/generators/resource_helpers.rb
@@ -9,14 +9,7 @@ module Rails
mattr_accessor :skip_warn
def self.included(base) #:nodoc:
- base.class_eval do
- 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
+ base.class_option :force_plural, :type => :boolean, :desc => "Forces the use of a plural ModelName"
end
# Set controller variables on initialization.
@@ -29,29 +22,40 @@ module Rails
say "Plural version of the model detected, using singularized version. Override with --force-plural."
ResourceHelpers.skip_warn = true
end
-
name.replace name.singularize
- assign_names!(self.name)
+ assign_names!(name)
end
@controller_name = name.pluralize
+ end
- base_name, @controller_class_path, @controller_file_path, class_nesting, class_nesting_depth = extract_modules(@controller_name)
- class_name_without_nesting, @controller_file_name, controller_plural_name = inflect_names(base_name)
+ protected
+
+ attr_reader :controller_name
- @controller_class_name = if class_nesting.empty?
- class_name_without_nesting
- else
- "#{class_nesting}::#{class_name_without_nesting}"
+ def controller_class_path
+ @class_path
end
- end
- protected
+ def controller_file_name
+ @controller_file_name ||= file_name.pluralize
+ end
+
+ def controller_file_path
+ @controller_file_path ||= (controller_class_path + [controller_file_name]).join('/')
+ end
+
+ def controller_class_name
+ @controller_class_name ||= (controller_class_path + [controller_file_name]).map!{ |m| m.camelize }.join('::')
+ end
+
+ def controller_i18n_scope
+ @controller_i18n_scope ||= controller_file_path.gsub('/', '.')
+ end
# Loads the ORM::Generators::ActiveModel class. This class is responsable
# to tell scaffold entities how to generate an specific method for the
# ORM. Check Rails::Generators::ActiveModel for more information.
- #
def orm_class
@orm_class ||= begin
# Raise an error if the class_option :orm was not defined.
@@ -68,7 +72,6 @@ module Rails
end
# Initialize ORM::Generators::ActiveModel to access instance methods.
- #
def orm_instance(name=file_name)
@orm_instance ||= @orm_class.new(name)
end