Class: AppGenerator

Inherits:
Rails::Generator::Base show all
Defined in:
lib/rails_generator/generators/applications/app/app_generator.rb

Constant Summary collapse

DEFAULT_SHEBANG =
File.join(Config::CONFIG['bindir'],
Config::CONFIG['ruby_install_name'])
DATABASES =
%w(mysql oracle postgresql sqlite2 sqlite3 frontbase)

Instance Attribute Summary

Attributes inherited from Rails::Generator::Base

#args, #destination_root, #source_root

Attributes included from Rails::Generator::Options

#options

Instance Method Summary collapse

Methods inherited from Rails::Generator::Base

#destination_path, #source_path

Methods included from Rails::Generator::Options

included

Constructor Details

#initialize(runtime_args, runtime_options = {}) ⇒ AppGenerator

Returns a new instance of AppGenerator.



12
13
14
15
16
17
18
# File 'lib/rails_generator/generators/applications/app/app_generator.rb', line 12

def initialize(runtime_args, runtime_options = {})
  super
  usage if args.empty?
  usage("Databases supported for preconfiguration are: #{DATABASES.join(", ")}") if (options[:db] && !DATABASES.include?(options[:db]))
  @destination_root = args.shift
  @app_name = File.basename(File.expand_path(@destination_root))
end

Instance Method Details

#manifestObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rails_generator/generators/applications/app/app_generator.rb', line 20

def manifest
  # Use /usr/bin/env if no special shebang was specified
  script_options     = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
  dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] }

  record do |m|
    # Root directory and all subdirectories.
    m.directory ''
    BASEDIRS.each { |path| m.directory path }

    # Root
    m.file "README", "README"

    # Application
    m.file "helpers/application.rb", "app/adaptors/application.rb"
    m.file "helpers/test_helper.rb", "test/test_helper.rb"
    m.file "helpers/publish.rb", "test/mocks/test/publish.rb"

    # database.yml 
    m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => {
      :app_name => @app_name,
      :socket   => options[:db] == "mysql" ? mysql_socket_location : nil
    }

    # mom.yml
    m.template "configs/mom.yml", "config/mom.yml"

    # settings.yml
    m.template "configs/settings.yml", "config/settings.yml"

    # boot.rb
    m.file "configs/boot.rb", "config/boot.rb"

    # Environments
    #m.file "environments/boot.rb",    "config/boot.rb"
    #m.template "environments/environment.rb", "config/environment.rb", :assigns => { :freeze => options[:freeze] }
    m.file "environments/environment.rb", "config/environment.rb"
    #m.file "environments/production.rb",  "config/environments/production.rb"
    m.file "environments/development.rb", "config/environments/development.rb"
    m.file "environments/test.rb",        "config/environments/test.rb"

    # Scripts
    %w( generate destroy about publish subscribe console ).each do |file|
      m.file "bin/#{file}", "script/#{file}", script_options
    end

    # Dispatches
    m.file "dispatches/dispatch.rb", "public/dispatch.rb", script_options

    # Docs
    m.file "doc/README_FOR_APP", "doc/README_FOR_APP"

    # Logs
    %w(subscriber development test).each { |file|
      m.file "configs/empty.log", "log/#{file}.log", :chmod => 0666
    }

    # Tests script
    m.file "helpers/test.rb", "test.rb"

  end
end