github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

rails / rails

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 4,951
    • 826
  • Source
  • Commits
  • Network (826)
  • Downloads (61)
  • Wiki (4)
  • Graphs
  • Tree: 73cc5f2

click here to add a description

click here to add a homepage

  • Branches (6)
    • 1-2-stable
    • 2-0-stable
    • 2-1-stable
    • 2-2-stable
    • 2-3-stable
    • master
  • Tags (61)
    • v3.0.0.beta1
    • v2.3.5
    • v2.3.4
    • v2.3.3.1
    • v2.3.3
    • v2.3.2.1
    • v2.3.2
    • v2.3.1
    • v2.3.0
    • v2.2.3
    • v2.2.2
    • v2.2.1
    • v2.2.0
    • v2.1.2
    • v2.1.1
    • v2.1.0_RC1
    • v2.1.0
    • v2.0.5
    • v2.0.4
    • v2.0.3
    • v2.0.2
    • v2.0.1
    • v2.0.0_RC2
    • v2.0.0_RC1
    • v2.0.0_PR
    • v2.0.0
    • v1.2.6
    • v1.2.5
    • v1.2.4
    • v1.2.3
    • v1.2.2
    • v1.2.1
    • v1.2.0_RC2
    • v1.2.0_RC1
    • v1.2.0
    • v1.1.6
    • v1.1.5
    • v1.1.4
    • v1.1.3
    • v1.1.2
    • v1.1.1
    • v1.1.0_RC1
    • v1.1.0
    • v1.0.0
    • v0.14.4
    • v0.14.3
    • v0.14.2
    • v0.14.1
    • v0.13.1
    • v0.13.0
    • v0.12.0
    • v0.11.1
    • v0.11.0
    • v0.10.1
    • v0.10.0
    • v0.9.5
    • v0.9.4.1
    • v0.9.4
    • v0.9.3
    • v0.9.2
    • v0.9.1
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Ruby on Rails — Read more

  cancel

http://rubyonrails.org

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Setup ActiveRecord QueryCache middleware in the initializer 
josh (author)
Wed Jan 21 10:44:07 -0800 2009
commit  73cc5f270a5c2a2eab76c6c02615fec608822494
tree    7d9a145c370a3fd6439edc6907504186415da126
parent  82334a74311a3e0a8a1454d0a4a2ebf3c1138cea
rails / railties / lib / rails_generator / generators / applications / app / app_generator.rb railties/lib/rails_generator/generators/applications/app/app_generator.rb
100644 258 lines (213 sloc) 8.354 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
require 'rbconfig'
require File.dirname(__FILE__) + '/template_runner'
require 'digest/md5'
require 'active_support/secure_random'
 
class AppGenerator < Rails::Generator::Base
  DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
 
  DATABASES = %w( mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db )
  DEFAULT_DATABASE = 'sqlite3'
 
  mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.."
  default_options :db => (ENV["RAILS_DEFAULT_DATABASE"] || DEFAULT_DATABASE),
    :shebang => DEFAULT_SHEBANG, :with_dispatchers => false, :freeze => false
 
 
  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
 
  def manifest
    record do |m|
      create_directories(m)
      create_root_files(m)
      create_app_files(m)
      create_config_files(m)
      create_script_files(m)
      create_test_files(m)
      create_public_files(m)
      create_documentation_file(m)
      create_log_files(m)
    end
  end
 
  def after_generate
    if options[:template]
      Rails::TemplateRunner.new(options[:template], @destination_root)
    end
  end
 
  protected
    def banner
      "Usage: #{$0} /path/to/your/app [options]"
    end
 
    def add_options!(opt)
      opt.separator ''
      opt.separator 'Options:'
      opt.on("-r", "--ruby=path", String,
             "Path to the Ruby binary of your choice (otherwise scripts use env, dispatchers current path).",
             "Default: #{DEFAULT_SHEBANG}") { |v| options[:shebang] = v }
 
      opt.on("-d", "--database=name", String,
            "Preconfigure for selected database (options: #{DATABASES.join('/')}).",
            "Default: #{DEFAULT_DATABASE}") { |v| options[:db] = v }
 
      opt.on("-D", "--with-dispatchers",
            "Add CGI/FastCGI/mod_ruby dispatches code to generated application skeleton",
            "Default: false") { |v| options[:with_dispatchers] = v }
 
      opt.on("-f", "--freeze",
            "Freeze Rails in vendor/rails from the gems generating the skeleton",
            "Default: false") { |v| options[:freeze] = v }
 
      opt.on("-m", "--template=path", String,
            "Use an application template that lives at path (can be a filesystem path or URL).",
            "Default: (none)") { |v| options[:template] = v }
 
    end
 
 
  private
    def create_directories(m)
      m.directory ''
 
      # Intermediate directories are automatically created so don't sweat their absence here.
      %w(
app/controllers
app/helpers
app/models
app/views/layouts
config/environments
config/initializers
config/locales
db
doc
lib
lib/tasks
log
public/images
public/javascripts
public/stylesheets
script/performance
test/fixtures
test/functional
test/integration
test/performance
test/unit
vendor
vendor/plugins
tmp/sessions
tmp/sockets
tmp/cache
tmp/pids
).each { |path| m.directory(path) }
    end
    
    def create_root_files(m)
      m.file "fresh_rakefile", "Rakefile"
      m.file "README", "README"
    end
    
    def create_app_files(m)
      m.file "helpers/application_controller.rb", "app/controllers/application_controller.rb"
      m.file "helpers/application_helper.rb", "app/helpers/application_helper.rb"
    end
 
    def create_config_files(m)
      create_database_configuration_file(m)
      create_routes_file(m)
      create_locale_file(m)
      create_initializer_files(m)
      create_environment_files(m)
    end
 
    def create_documentation_file(m)
      m.file "doc/README_FOR_APP", "doc/README_FOR_APP"
    end
 
    def create_log_files(m)
      %w( server production development test ).each do |file|
        m.file "configs/empty.log", "log/#{file}.log", :chmod => 0666
      end
    end
 
    def create_public_files(m)
      create_dispatch_files(m)
      create_error_files(m)
      create_welcome_file(m)
      create_browser_convention_files(m)
      create_rails_image(m)
      create_javascript_files(m)
    end
    
    def create_script_files(m)
      %w(
about console dbconsole destroy generate runner server plugin
performance/benchmarker performance/profiler
).each do |file|
        m.file "bin/#{file}", "script/#{file}", {
          :chmod => 0755,
          :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang]
        }
      end
    end
 
    def create_test_files(m)
      m.file "helpers/test_helper.rb", "test/test_helper.rb"
      m.file "helpers/performance_test.rb", "test/performance/browsing_test.rb"
    end
 
 
    def create_database_configuration_file(m)
      m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => {
        :app_name => @app_name,
        :socket => options[:db] == "mysql" ? mysql_socket_location : nil }
    end
    
    def create_routes_file(m)
      m.file "configs/routes.rb", "config/routes.rb"
    end
 
    def create_initializer_files(m)
      %w(
backtrace_silencers
inflections
mime_types
new_rails_defaults
).each do |initializer|
        m.file "configs/initializers/#{initializer}.rb", "config/initializers/#{initializer}.rb"
      end
 
      m.template "configs/initializers/session_store.rb", "config/initializers/session_store.rb",
        :assigns => { :app_name => @app_name, :app_secret => ActiveSupport::SecureRandom.hex(64) }
    end
 
    def create_locale_file(m)
      m.file "configs/locales/en.yml", "config/locales/en.yml"
    end
 
    def create_environment_files(m)
      m.template "environments/environment.rb", "config/environment.rb",
        :assigns => { :freeze => options[:freeze] }
 
      m.file "environments/boot.rb", "config/boot.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"
    end
 
 
    def create_dispatch_files(m)
      if options[:with_dispatchers]
        dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] }
 
        m.file "dispatches/config.ru", "config.ru"
        m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options
        m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options
        m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options
      end
    end
 
    def create_error_files(m)
      %w( 404 422 500 ).each do |file|
        m.file "html/#{file}.html", "public/#{file}.html"
      end
    end
 
    def create_welcome_file(m)
      m.file 'html/index.html', 'public/index.html'
    end
 
    def create_browser_convention_files(m)
      m.file "html/favicon.ico", "public/favicon.ico"
      m.file "html/robots.txt", "public/robots.txt"
    end
 
    def create_rails_image(m)
      m.file "html/images/rails.png", "public/images/rails.png"
    end
 
    def create_javascript_files(m)
      %w( prototype effects dragdrop controls application ).each do |javascript|
        m.file "html/javascripts/#{javascript}.js", "public/javascripts/#{javascript}.js"
      end
    end
 
 
    def mysql_socket_location
      [
        "/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 RUBY_PLATFORM =~ /(:?mswin|mingw)/
    end
end
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server