aboutsummaryrefslogblamecommitdiffstats
path: root/railties/lib/generators/rails/resource/resource_generator.rb
blob: 5acb839f39ad14aa65e8e8d2e7c049436e6cb347 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                                           
                                                


                   
                                                           

                             

                                                                      
         
 
                                                                                         
                                                                           
 
                                                                                                    
 
                            
                                                                                  

         









                                


       
require 'rails/generators/resource_helpers'
require 'generators/rails/model/model_generator'

module Rails
  module Generators
    class ResourceGenerator < ModelGenerator #metagenerator
      include ResourceHelpers

      hook_for :resource_controller, :required => true do |controller|
        invoke controller, [ controller_name, options[:actions] ]
      end

      class_option :actions, :type => :array, :banner => "ACTION ACTION", :default => [],
                             :desc => "Actions for the resource controller"

      class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"

      def add_resource_route
        route "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