Class: Merb::Generators::ResourceControllerGenerator
Class Method Summary
collapse
Instance Method Summary
collapse
#base_path, #class_name, #file_name, #full_class_name, #modules
#class_name, #file_name, #initialize, #symbol_name, #test_class_name
Methods inherited from Generator
#go_up, #initialize, #with_modules
#error, #success, #warning
Class Method Details
.source_root ⇒ Object
5
6
7
|
# File 'lib/generators/resource_controller.rb', line 5
def self.source_root
File.join(super, 'component', 'resource_controller')
end
|
Instance Method Details
#add_resource_route(plural_resource) ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/generators/resource_controller.rb', line 53
def add_resource_route(plural_resource)
router_path = Merb.root + "/config/router.rb"
sentinel = "Merb::Router.prepare do"
to_inject = "resources :#{plural_resource}"
if File.exist?(router_path)
content = File.read(router_path).gsub(/(#{Regexp.escape(sentinel)})/mi){|match| "#{match}\n #{to_inject}"}
File.open(router_path, 'wb') { |file| file.write(content) }
end
end
|
#model_class_name ⇒ Object
63
64
65
|
# File 'lib/generators/resource_controller.rb', line 63
def model_class_name
class_name.singularize
end
|
#params_for_get ⇒ Object
TODO: fix this for Datamapper, so that it returns the primary keys for the model
80
81
82
|
# File 'lib/generators/resource_controller.rb', line 80
def params_for_get
"params[:id]"
end
|
#plural_model ⇒ Object
67
68
69
|
# File 'lib/generators/resource_controller.rb', line 67
def plural_model
class_name.snake_case
end
|
#properties ⇒ Object
TODO: implement this for Datamapper so that we get the model properties
85
86
87
|
# File 'lib/generators/resource_controller.rb', line 85
def properties
[]
end
|
#resource_path ⇒ Object
75
76
77
|
# File 'lib/generators/resource_controller.rb', line 75
def resource_path
chunks.map{ |c| c.snake_case }.join('/')
end
|
#singular_model ⇒ Object
71
72
73
|
# File 'lib/generators/resource_controller.rb', line 71
def singular_model
plural_model.singularize
end
|
#skip_route_definition? ⇒ Boolean
89
90
91
|
# File 'lib/generators/resource_controller.rb', line 89
def skip_route_definition?
options[:pretend] || options[:delete]
end
|