Parent

Merb::Generators::ResourceControllerGenerator

Public Class Methods

source_root() click to toggle source
# File lib/generators/resource_controller.rb, line 5
def self.source_root
  File.join(super, 'component', 'resource_controller')
end

Public Instance Methods

add_resource_route(plural_resource) click to toggle source
# 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)})/i){|match| "#{match}\n  #{to_inject}"}
    File.open(router_path, 'wb') { |file| file.write(content) }
  end
end
model_class_name() click to toggle source
# File lib/generators/resource_controller.rb, line 63
def model_class_name
  class_name.singularize
end
params_for_get() click to toggle source

TODO: fix this for Datamapper, so that it returns the primary keys for the model

# File lib/generators/resource_controller.rb, line 80
def params_for_get
  "params[:id]"
end
plural_model() click to toggle source
# File lib/generators/resource_controller.rb, line 67
def plural_model
  class_name.snake_case
end
properties() click to toggle source

TODO: implement this for Datamapper so that we get the model properties

# File lib/generators/resource_controller.rb, line 85
def properties
  []
end
resource_path() click to toggle source
# File lib/generators/resource_controller.rb, line 75
def resource_path
  chunks.map{ |c| c.snake_case }.join('/')
end
singular_model() click to toggle source
# File lib/generators/resource_controller.rb, line 71
def singular_model
  plural_model.singularize
end
skip_route_definition?() click to toggle source
# File lib/generators/resource_controller.rb, line 89
def skip_route_definition?
  options[:pretend] || options[:delete]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.