Class: Merb::Generators::ResourceControllerGenerator
- Inherits:
-
NamespacedGenerator
- Object
- Templater::Generator
- Generator
- NamedGenerator
- NamespacedGenerator
- Merb::Generators::ResourceControllerGenerator
- Defined in:
- lib/generators/resource_controller.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_resource_route(plural_resource) ⇒ Object
- #model_class_name ⇒ Object
-
#params_for_get ⇒ Object
TODO: fix this for Datamapper, so that it returns the primary keys for the model.
- #plural_model ⇒ Object
-
#properties ⇒ Object
TODO: implement this for Datamapper so that we get the model properties.
- #resource_path ⇒ Object
- #singular_model ⇒ Object
Methods inherited from NamespacedGenerator
#base_path, #class_name, #file_name, #full_class_name, #modules
Methods inherited from NamedGenerator
#class_name, #file_name, #initialize, #symbol_name, #test_class_name
Methods inherited from Generator
#go_up, #initialize, #with_modules
Methods included from ColorfulMessages
Constructor Details
This class inherits a constructor from Merb::Generators::NamedGenerator
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
54 55 56 57 58 59 60 61 62 |
# File 'lib/generators/resource_controller.rb', line 54 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
64 65 66 |
# File 'lib/generators/resource_controller.rb', line 64 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
81 82 83 |
# File 'lib/generators/resource_controller.rb', line 81 def params_for_get "params[:id]" end |
#plural_model ⇒ Object
68 69 70 |
# File 'lib/generators/resource_controller.rb', line 68 def plural_model class_name.snake_case end |
#properties ⇒ Object
TODO: implement this for Datamapper so that we get the model properties
86 87 88 |
# File 'lib/generators/resource_controller.rb', line 86 def properties [] end |
#resource_path ⇒ Object
76 77 78 |
# File 'lib/generators/resource_controller.rb', line 76 def resource_path chunks.map{ |c| c.snake_case }.join('/') end |
#singular_model ⇒ Object
72 73 74 |
# File 'lib/generators/resource_controller.rb', line 72 def singular_model plural_model.singularize end |