Class: Merb::Generators::ResourceControllerGenerator

Inherits:
NamespacedGenerator show all
Defined in:
lib/generators/resource_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

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

#error, #success, #warning

Constructor Details

This class inherits a constructor from Merb::Generators::NamedGenerator

Class Method Details

.source_rootObject



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_nameObject



63
64
65
# File 'lib/generators/resource_controller.rb', line 63

def model_class_name
  class_name.singularize
end

#params_for_getObject

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_modelObject



67
68
69
# File 'lib/generators/resource_controller.rb', line 67

def plural_model
  class_name.snake_case
end

#propertiesObject

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_pathObject



75
76
77
# File 'lib/generators/resource_controller.rb', line 75

def resource_path
  chunks.map{ |c| c.snake_case }.join('/')
end

#singular_modelObject



71
72
73
# File 'lib/generators/resource_controller.rb', line 71

def singular_model
  plural_model.singularize
end

#skip_route_definition?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/generators/resource_controller.rb', line 89

def skip_route_definition?
  options[:pretend] || options[:delete]
end