class Rails::Generators::AppGenerator

def self.banner

def self.banner
  "rails new #{self.arguments.map(&:usage).join(' ')} [options]"
end

def app_const

def app_const
  @app_const ||= "#{app_const_base}::Application"
end

def app_const_base

def app_const_base
  @app_const_base ||= defined_app_const_base || app_name.gsub(/\W/, '_').squeeze('_').camelize
end

def app_name

def app_name
  @app_name ||= defined_app_const_base? ? defined_app_name : File.basename(destination_root)
end

def app_secret

def app_secret
  ActiveSupport::SecureRandom.hex(64)
end

def apply_rails_template

def apply_rails_template
  apply rails_template if rails_template
rescue Thor::Error, LoadError, Errno::ENOENT => e
  raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}"
end

def build(meth, *args)

def build(meth, *args)
  builder.send(meth, *args) if builder.respond_to?(meth)
end

def builder

def builder
  @builder ||= begin
    if path = options[:builder]
      if URI(path).is_a?(URI::HTTP)
        contents = open(path, "Accept" => "application/x-thor-template") {|io| io.read }
      else
        contents = open(File.expand_path(path, @original_wd)) {|io| io.read }
      end
      prok = eval("proc { #{contents} }", TOPLEVEL_BINDING, path, 1)
      instance_eval(&prok)
    end
    builder_class = defined?(::AppBuilder) ? ::AppBuilder : Rails::AppBuilder
    builder_class.send(:include, ActionMethods)
    builder_class.new(self)
  end
end

def bundle_if_dev_or_edge

def bundle_if_dev_or_edge
  bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
  run "#{bundle_command} install" if dev_or_edge?
end

def create_active_record_files

def create_active_record_files
  return if options[:skip_active_record]
  build(:database_yml)
end

def create_app_files

def create_app_files
  build(:app)
end

def create_boot_file

def create_boot_file
  template "config/boot.rb"
end

def create_config_files

def create_config_files
  build(:config)
end

def create_db_files

def create_db_files
  build(:db)
end

def create_doc_files

def create_doc_files
  build(:doc)
end

def create_lib_files

def create_lib_files
  build(:lib)
end

def create_log_files

def create_log_files
  build(:log)
end

def create_prototype_files

def create_prototype_files
  build(:javascripts)
end

def create_public_files

def create_public_files
  build(:public_directory)
end

def create_public_image_files

def create_public_image_files
  build(:images)
end

def create_public_stylesheets_files

def create_public_stylesheets_files
  build(:stylesheets)
end

def create_root

def create_root
  self.destination_root = File.expand_path(app_path, destination_root)
  valid_app_const?
  empty_directory '.'
  set_default_accessors!
  FileUtils.cd(destination_root) unless options[:pretend]
end

def create_root_files

def create_root_files
  build(:readme)
  build(:rakefile)
  build(:configru)
  build(:gitignore) unless options[:skip_git]
  build(:gemfile)   unless options[:skip_gemfile]
end

def create_script_files

def create_script_files
  build(:script)
end

def create_test_files

def create_test_files
  build(:test) unless options[:skip_test_unit]
end

def create_tmp_files

def create_tmp_files
  build(:tmp)
end

def create_vendor_files

def create_vendor_files
  build(:vendor_plugins)
end

def defined_app_const_base

def defined_app_const_base
  Rails.respond_to?(:application) && defined?(Rails::Application) &&
    Rails.application.is_a?(Rails::Application) && Rails.application.class.name.sub(/::Application$/, "")
end

def defined_app_name

def defined_app_name
  defined_app_const_base.underscore
end

def dev_or_edge?

def dev_or_edge?
  options.dev? || options.edge?
end

def empty_directory_with_gitkeep(destination, config = {})

def empty_directory_with_gitkeep(destination, config = {})
  empty_directory(destination, config)
  create_file("#{destination}/.gitkeep") unless options[:skip_git]
end

def file(*args, &block)

Define file as an alias to create_file for backwards compatibility.
def file(*args, &block)
  create_file(*args, &block)
end

def finish_template

def finish_template
  build(:leftovers)
end

def gem_for_database

def gem_for_database
  # %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
  case options[:database]
  when "oracle"     then "ruby-oci8"
  when "postgresql" then "pg"
  when "sqlite3"    then "sqlite3"
  when "frontbase"  then "ruby-frontbase"
  when "mysql"      then "mysql2"
  else options[:database]
  end
end

def initialize(*args)

def initialize(*args)
  raise Error, "Options should be given after the application name. For details run: rails --help" if args[0].blank?
  @original_wd = Dir.pwd
  super
  if !options[:skip_active_record] && !DATABASES.include?(options[:database])
    raise Error, "Invalid value for --database option. Supported for preconfiguration are: #{DATABASES.join(", ")}."
  end
end

def mysql_socket

def mysql_socket
  @mysql_socket ||= [
    "/tmp/mysql.sock",                        # default
    "/var/run/mysqld/mysqld.sock",            # debian/gentoo
    "/var/tmp/mysql.sock",                    # freebsd
    "/var/lib/mysql/mysql.sock",              # fedora
    "/opt/local/lib/mysql/mysql.sock",        # fedora
    "/opt/local/var/run/mysqld/mysqld.sock",  # mac + darwinports + mysql
    "/opt/local/var/run/mysql4/mysqld.sock",  # mac + darwinports + mysql4
    "/opt/local/var/run/mysql5/mysqld.sock",  # mac + darwinports + mysql5
    "/opt/lampp/var/mysql/mysql.sock"         # xampp for linux
  ].find { |f| File.exist?(f) } unless RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
end

def set_default_accessors!

def set_default_accessors!
  self.rails_template = case options[:template]
    when /^https?:\/\//
      options[:template]
    when String
      File.expand_path(options[:template], Dir.pwd)
    else
      options[:template]
  end
end

def valid_app_const?

def valid_app_const?
  if app_const =~ /^\d/
    raise Error, "Invalid application name #{app_name}. Please give a name which does not start with numbers."
  elsif RESERVED_NAMES.include?(app_name)
    raise Error, "Invalid application name #{app_name}. Please give a name which does not match one of the reserved rails words."
  elsif Object.const_defined?(app_const_base)
    raise Error, "Invalid application name #{app_name}, constant #{app_const_base} is already in use. Please choose another application name."
  end
end