diff options
author | José Valim <jose.valim@gmail.com> | 2009-06-28 19:57:00 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-06-28 19:57:00 +0200 |
commit | ff4c6004484a3201f28f7512531c4e8f5f58b617 (patch) | |
tree | 3af1cdd1a084f9533e5106763d4c1a40e6c7ab07 /railties/lib/generators/rails | |
parent | 9413dba432b11d86b80449ca7b959b32ecb0844c (diff) | |
download | rails-ff4c6004484a3201f28f7512531c4e8f5f58b617.tar.gz rails-ff4c6004484a3201f28f7512531c4e8f5f58b617.tar.bz2 rails-ff4c6004484a3201f28f7512531c4e8f5f58b617.zip |
Added singleton support to resource controller.
Diffstat (limited to 'railties/lib/generators/rails')
-rw-r--r-- | railties/lib/generators/rails/resource/resource_generator.rb | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/railties/lib/generators/rails/resource/resource_generator.rb b/railties/lib/generators/rails/resource/resource_generator.rb index 938fd6298c..f61e55a01e 100644 --- a/railties/lib/generators/rails/resource/resource_generator.rb +++ b/railties/lib/generators/rails/resource/resource_generator.rb @@ -8,6 +8,9 @@ module Rails class_option :actions, :type => :array, :default => [], :banner => "ACTION ACTION", :desc => "Actions for the resource controller", :aliases => "-a" + class_option :singleton, :type => :boolean, :default => false, :aliases => "-i", + :desc => "Supply to create a singleton controller" + def invoke_for_resource_controller return unless options[:resource_controller] @@ -15,7 +18,7 @@ module Rails if klass args = [] - args << class_name.pluralize + args << pluralize?(class_name) args << options[:actions] say_status :invoke, options[:resource_controller], :blue @@ -25,11 +28,20 @@ module Rails end end - # TODO Add singleton support def add_resource_route - route "map.resources :#{file_name.pluralize}" + route "map.resource#{"s" unless options[:singleton]} :#{pluralize?(file_name)}" end + protected + + def pluralize?(name) + if options[:singleton] + name + else + name.pluralize + end + end + end end end |