class Mandrill::Rails::Generators::MandrillGenerator

Attributes

file_name[R]

Public Class Methods

new(args, *options) click to toggle source
Calls superclass method
# File lib/generators/mandrill/mandrill_generator.rb, line 19
def initialize(args, *options)
  args[0] = args[0].dup if args[0].is_a?(String) && args[0].frozen?
  super
  assign_names!(self.name)
end

Public Instance Methods

add_controller() click to toggle source
# File lib/generators/mandrill/mandrill_generator.rb, line 36
def add_controller
  return unless options.controller?
  @controller_name = class_name
  template 'controller.rb', controller_destination
end
add_routes() click to toggle source
# File lib/generators/mandrill/mandrill_generator.rb, line 25
def add_routes
  return unless options.routes?
  hook_route = "resource :#{resource_name}"

  controller = controller_path

  hook_route << %Q(, :controller => '#{controller}')
  hook_route << %Q(, :only => [:show,:create])
  route hook_route
end

Private Instance Methods

assign_names!(name) click to toggle source
# File lib/generators/mandrill/mandrill_generator.rb, line 46
def assign_names!(name)
  @class_path = name.include?('/') ? name.split('/') : name.split('::')
  @class_path.map!(&:underscore)
  @file_name = @class_path.pop
end
class_name() click to toggle source
# File lib/generators/mandrill/mandrill_generator.rb, line 52
def class_name
  @class_name ||= (@class_path + [resource_name]).map!(&:camelize).join('::')
end
controller_destination() click to toggle source
# File lib/generators/mandrill/mandrill_generator.rb, line 56
def controller_destination
  "app/controllers/#{controller_path}_controller.rb"
end
controller_path() click to toggle source
# File lib/generators/mandrill/mandrill_generator.rb, line 60
def controller_path
  @controller_path ||= if class_name.include?('::')
    @class_path.collect {|dname| dname }.join + "/" + resource_name
  else
    resource_name
  end
end
plural_name() click to toggle source
# File lib/generators/mandrill/mandrill_generator.rb, line 68
def plural_name
  @plural_name ||= singular_name.pluralize
end
resource_name() click to toggle source
# File lib/generators/mandrill/mandrill_generator.rb, line 72
def resource_name
  return singular_name unless options.pluralize_names?
  plural_name
end
singular_name() click to toggle source
# File lib/generators/mandrill/mandrill_generator.rb, line 77
def singular_name
  file_name.downcase
end