blob: 8a46708009579ef5bd19c0bee41686b566ee7517 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
require 'rails/generators/resource_helpers'
require 'rails/generators/rails/model/model_generator'
require 'active_support/core_ext/object/blank'
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
return if options[:actions].present?
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
|