erails 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. data/CHANGELOG +3 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +309 -0
  4. data/Rakefile +339 -0
  5. data/bin/about +4 -0
  6. data/bin/console +3 -0
  7. data/bin/dbconsole +3 -0
  8. data/bin/destroy +3 -0
  9. data/bin/erails +19 -0
  10. data/bin/generate +3 -0
  11. data/bin/performance/benchmarker +3 -0
  12. data/bin/performance/profiler +3 -0
  13. data/bin/performance/request +3 -0
  14. data/bin/plugin +3 -0
  15. data/bin/process/inspector +3 -0
  16. data/bin/process/reaper +3 -0
  17. data/bin/process/spawner +3 -0
  18. data/bin/runner +3 -0
  19. data/bin/server +3 -0
  20. data/builtin/rails_info/rails/info.rb +125 -0
  21. data/builtin/rails_info/rails/info_controller.rb +9 -0
  22. data/builtin/rails_info/rails/info_helper.rb +2 -0
  23. data/builtin/rails_info/rails_info_controller.rb +2 -0
  24. data/configs/apache.conf +40 -0
  25. data/configs/databases/frontbase.yml +28 -0
  26. data/configs/databases/mysql.yml +54 -0
  27. data/configs/databases/oracle.yml +39 -0
  28. data/configs/databases/postgresql.yml +48 -0
  29. data/configs/databases/sqlite2.yml +16 -0
  30. data/configs/databases/sqlite3.yml +19 -0
  31. data/configs/empty.log +0 -0
  32. data/configs/initializers/inflections.rb +10 -0
  33. data/configs/initializers/mime_types.rb +5 -0
  34. data/configs/initializers/new_rails_defaults.rb +17 -0
  35. data/configs/lighttpd.conf +54 -0
  36. data/configs/routes.rb +43 -0
  37. data/dispatches/dispatch.fcgi +24 -0
  38. data/dispatches/dispatch.rb +10 -0
  39. data/dispatches/gateway.cgi +97 -0
  40. data/doc/README_FOR_APP +2 -0
  41. data/environments/boot.rb +109 -0
  42. data/environments/development.rb +16 -0
  43. data/environments/environment.rb +71 -0
  44. data/environments/production.rb +22 -0
  45. data/environments/test.rb +22 -0
  46. data/fresh_rakefile +10 -0
  47. data/helpers/application.rb +15 -0
  48. data/helpers/application_helper.rb +3 -0
  49. data/helpers/test_helper.rb +38 -0
  50. data/html/404.html +30 -0
  51. data/html/422.html +30 -0
  52. data/html/500.html +30 -0
  53. data/html/favicon.ico +0 -0
  54. data/html/images/rails.png +0 -0
  55. data/html/index.html +274 -0
  56. data/html/javascripts/application.js +2 -0
  57. data/html/robots.txt +5 -0
  58. data/lib/code_statistics.rb +107 -0
  59. data/lib/commands/about.rb +3 -0
  60. data/lib/commands/console.rb +32 -0
  61. data/lib/commands/dbconsole.rb +67 -0
  62. data/lib/commands/destroy.rb +6 -0
  63. data/lib/commands/generate.rb +6 -0
  64. data/lib/commands/ncgi/listener +86 -0
  65. data/lib/commands/ncgi/tracker +69 -0
  66. data/lib/commands/performance/benchmarker.rb +24 -0
  67. data/lib/commands/performance/profiler.rb +50 -0
  68. data/lib/commands/performance/request.rb +6 -0
  69. data/lib/commands/plugin.rb +950 -0
  70. data/lib/commands/process/inspector.rb +68 -0
  71. data/lib/commands/process/reaper.rb +149 -0
  72. data/lib/commands/process/spawner.rb +219 -0
  73. data/lib/commands/process/spinner.rb +57 -0
  74. data/lib/commands/runner.rb +48 -0
  75. data/lib/commands/server.rb +39 -0
  76. data/lib/commands/servers/base.rb +31 -0
  77. data/lib/commands/servers/lighttpd.rb +94 -0
  78. data/lib/commands/servers/mongrel.rb +69 -0
  79. data/lib/commands/servers/new_mongrel.rb +16 -0
  80. data/lib/commands/servers/webrick.rb +66 -0
  81. data/lib/commands/update.rb +4 -0
  82. data/lib/commands.rb +17 -0
  83. data/lib/console_app.rb +30 -0
  84. data/lib/console_sandbox.rb +6 -0
  85. data/lib/console_with_helpers.rb +26 -0
  86. data/lib/dispatcher.rb +24 -0
  87. data/lib/fcgi_handler.rb +239 -0
  88. data/lib/initializer.rb +926 -0
  89. data/lib/rails/gem_builder.rb +21 -0
  90. data/lib/rails/gem_dependency.rb +129 -0
  91. data/lib/rails/mongrel_server/commands.rb +342 -0
  92. data/lib/rails/mongrel_server/handler.rb +55 -0
  93. data/lib/rails/plugin/loader.rb +152 -0
  94. data/lib/rails/plugin/locator.rb +100 -0
  95. data/lib/rails/plugin.rb +116 -0
  96. data/lib/rails/version.rb +9 -0
  97. data/lib/rails_generator/base.rb +263 -0
  98. data/lib/rails_generator/commands.rb +622 -0
  99. data/lib/rails_generator/generated_attribute.rb +42 -0
  100. data/lib/rails_generator/generators/applications/app/USAGE +9 -0
  101. data/lib/rails_generator/generators/applications/app/app_generator.rb +174 -0
  102. data/lib/rails_generator/generators/components/controller/USAGE +29 -0
  103. data/lib/rails_generator/generators/components/controller/controller_generator.rb +37 -0
  104. data/lib/rails_generator/generators/components/controller/templates/controller.rb +7 -0
  105. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +8 -0
  106. data/lib/rails_generator/generators/components/controller/templates/helper.rb +2 -0
  107. data/lib/rails_generator/generators/components/controller/templates/view.html.erb +2 -0
  108. data/lib/rails_generator/generators/components/integration_test/USAGE +8 -0
  109. data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +16 -0
  110. data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +10 -0
  111. data/lib/rails_generator/generators/components/mailer/USAGE +16 -0
  112. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +30 -0
  113. data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +3 -0
  114. data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -0
  115. data/lib/rails_generator/generators/components/mailer/templates/mailer.rb +15 -0
  116. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +21 -0
  117. data/lib/rails_generator/generators/components/mailer/templates/view.erb +3 -0
  118. data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -0
  119. data/lib/rails_generator/generators/components/migration/USAGE +29 -0
  120. data/lib/rails_generator/generators/components/migration/migration_generator.rb +20 -0
  121. data/lib/rails_generator/generators/components/migration/templates/migration.rb +11 -0
  122. data/lib/rails_generator/generators/components/model/USAGE +27 -0
  123. data/lib/rails_generator/generators/components/model/model_generator.rb +45 -0
  124. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +19 -0
  125. data/lib/rails_generator/generators/components/model/templates/migration.rb +16 -0
  126. data/lib/rails_generator/generators/components/model/templates/model.rb +2 -0
  127. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +8 -0
  128. data/lib/rails_generator/generators/components/observer/USAGE +13 -0
  129. data/lib/rails_generator/generators/components/observer/observer_generator.rb +16 -0
  130. data/lib/rails_generator/generators/components/observer/templates/observer.rb +2 -0
  131. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +8 -0
  132. data/lib/rails_generator/generators/components/plugin/USAGE +25 -0
  133. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +39 -0
  134. data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +20 -0
  135. data/lib/rails_generator/generators/components/plugin/templates/README +13 -0
  136. data/lib/rails_generator/generators/components/plugin/templates/Rakefile +22 -0
  137. data/lib/rails_generator/generators/components/plugin/templates/USAGE +8 -0
  138. data/lib/rails_generator/generators/components/plugin/templates/generator.rb +8 -0
  139. data/lib/rails_generator/generators/components/plugin/templates/init.rb +1 -0
  140. data/lib/rails_generator/generators/components/plugin/templates/install.rb +1 -0
  141. data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +1 -0
  142. data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +4 -0
  143. data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +1 -0
  144. data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +8 -0
  145. data/lib/rails_generator/generators/components/resource/USAGE +23 -0
  146. data/lib/rails_generator/generators/components/resource/resource_generator.rb +74 -0
  147. data/lib/rails_generator/generators/components/resource/templates/controller.rb +2 -0
  148. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +8 -0
  149. data/lib/rails_generator/generators/components/resource/templates/helper.rb +2 -0
  150. data/lib/rails_generator/generators/components/scaffold/USAGE +25 -0
  151. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +93 -0
  152. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +85 -0
  153. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +45 -0
  154. data/lib/rails_generator/generators/components/scaffold/templates/helper.rb +2 -0
  155. data/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb +17 -0
  156. data/lib/rails_generator/generators/components/scaffold/templates/style.css +54 -0
  157. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +18 -0
  158. data/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +24 -0
  159. data/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +17 -0
  160. data/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb +10 -0
  161. data/lib/rails_generator/generators/components/session_migration/USAGE +10 -0
  162. data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +18 -0
  163. data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +16 -0
  164. data/lib/rails_generator/lookup.rb +249 -0
  165. data/lib/rails_generator/manifest.rb +53 -0
  166. data/lib/rails_generator/options.rb +150 -0
  167. data/lib/rails_generator/scripts/destroy.rb +30 -0
  168. data/lib/rails_generator/scripts/generate.rb +7 -0
  169. data/lib/rails_generator/scripts/update.rb +12 -0
  170. data/lib/rails_generator/scripts.rb +89 -0
  171. data/lib/rails_generator/secret_key_generator.rb +164 -0
  172. data/lib/rails_generator/simple_logger.rb +46 -0
  173. data/lib/rails_generator/spec.rb +44 -0
  174. data/lib/rails_generator.rb +43 -0
  175. data/lib/railties_path.rb +1 -0
  176. data/lib/ruby_version_check.rb +17 -0
  177. data/lib/rubyprof_ext.rb +35 -0
  178. data/lib/source_annotation_extractor.rb +102 -0
  179. data/lib/tasks/annotations.rake +23 -0
  180. data/lib/tasks/databases.rake +389 -0
  181. data/lib/tasks/documentation.rake +80 -0
  182. data/lib/tasks/framework.rake +105 -0
  183. data/lib/tasks/gems.rake +64 -0
  184. data/lib/tasks/log.rake +9 -0
  185. data/lib/tasks/misc.rake +57 -0
  186. data/lib/tasks/rails.rb +8 -0
  187. data/lib/tasks/routes.rake +17 -0
  188. data/lib/tasks/statistics.rake +18 -0
  189. data/lib/tasks/testing.rake +118 -0
  190. data/lib/tasks/tmp.rake +37 -0
  191. data/lib/test_help.rb +28 -0
  192. data/lib/webrick_server.rb +165 -0
  193. metadata +356 -0
@@ -0,0 +1,926 @@
1
+ require 'logger'
2
+ require 'set'
3
+ require 'pathname'
4
+
5
+ $LOAD_PATH.unshift File.dirname(__FILE__)
6
+ require 'railties_path'
7
+ require 'rails/version'
8
+ require 'rails/plugin/locator'
9
+ require 'rails/plugin/loader'
10
+ require 'rails/gem_dependency'
11
+
12
+
13
+ RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
14
+
15
+ module Rails
16
+ class << self
17
+ # The Configuration instance used to configure the Rails environment
18
+ def configuration
19
+ @@configuration
20
+ end
21
+
22
+ def configuration=(configuration)
23
+ @@configuration = configuration
24
+ end
25
+
26
+ def logger
27
+ RAILS_DEFAULT_LOGGER
28
+ end
29
+
30
+ def root
31
+ if defined?(RAILS_ROOT)
32
+ RAILS_ROOT
33
+ else
34
+ nil
35
+ end
36
+ end
37
+
38
+ def env
39
+ require 'active_support/string_inquirer'
40
+ ActiveSupport::StringInquirer.new(RAILS_ENV)
41
+ end
42
+
43
+ def cache
44
+ RAILS_CACHE
45
+ end
46
+
47
+ def version
48
+ VERSION::STRING
49
+ end
50
+
51
+ def public_path
52
+ @@public_path ||= self.root ? File.join(self.root, "public") : "public"
53
+ end
54
+
55
+ def public_path=(path)
56
+ @@public_path = path
57
+ end
58
+ end
59
+
60
+ # The Initializer is responsible for processing the Rails configuration, such
61
+ # as setting the $LOAD_PATH, requiring the right frameworks, initializing
62
+ # logging, and more. It can be run either as a single command that'll just
63
+ # use the default configuration, like this:
64
+ #
65
+ # Rails::Initializer.run
66
+ #
67
+ # But normally it's more interesting to pass in a custom configuration
68
+ # through the block running:
69
+ #
70
+ # Rails::Initializer.run do |config|
71
+ # config.frameworks -= [ :action_mailer ]
72
+ # end
73
+ #
74
+ # This will use the default configuration options from Rails::Configuration,
75
+ # but allow for overwriting on select areas.
76
+ class Initializer
77
+ # The Configuration instance used by this Initializer instance.
78
+ attr_reader :configuration
79
+
80
+ # The set of loaded plugins.
81
+ attr_reader :loaded_plugins
82
+
83
+ # Whether or not all the gem dependencies have been met
84
+ attr_reader :gems_dependencies_loaded
85
+
86
+ # Runs the initializer. By default, this will invoke the #process method,
87
+ # which simply executes all of the initialization routines. Alternately,
88
+ # you can specify explicitly which initialization routine you want:
89
+ #
90
+ # Rails::Initializer.run(:set_load_path)
91
+ #
92
+ # This is useful if you only want the load path initialized, without
93
+ # incuring the overhead of completely loading the entire environment.
94
+ def self.run(command = :process, configuration = Configuration.new)
95
+ yield configuration if block_given?
96
+ initializer = new configuration
97
+ initializer.send(command)
98
+ initializer
99
+ end
100
+
101
+ # Create a new Initializer instance that references the given Configuration
102
+ # instance.
103
+ def initialize(configuration)
104
+ @configuration = configuration
105
+ @loaded_plugins = []
106
+ end
107
+
108
+ # Sequentially step through all of the available initialization routines,
109
+ # in order (view execution order in source).
110
+ def process
111
+ Rails.configuration = configuration
112
+
113
+ check_ruby_version
114
+ install_gem_spec_stubs
115
+ set_load_path
116
+ add_gem_load_paths
117
+
118
+ require_frameworks
119
+ set_autoload_paths
120
+ add_plugin_load_paths
121
+ load_environment
122
+
123
+ initialize_encoding
124
+ initialize_database
125
+
126
+ initialize_cache
127
+ initialize_framework_caches
128
+
129
+ initialize_logger
130
+ initialize_framework_logging
131
+
132
+ initialize_framework_views
133
+ initialize_dependency_mechanism
134
+ initialize_whiny_nils
135
+ initialize_temporary_session_directory
136
+ initialize_time_zone
137
+ initialize_framework_settings
138
+
139
+ add_support_load_paths
140
+
141
+ load_gems
142
+ load_plugins
143
+
144
+ # pick up any gems that plugins depend on
145
+ add_gem_load_paths
146
+ load_gems
147
+ check_gem_dependencies
148
+
149
+ load_application_initializers
150
+
151
+ # the framework is now fully initialized
152
+ after_initialize
153
+
154
+ # Prepare dispatcher callbacks and run 'prepare' callbacks
155
+ prepare_dispatcher
156
+
157
+ # Routing must be initialized after plugins to allow the former to extend the routes
158
+ initialize_routing
159
+
160
+ # Observers are loaded after plugins in case Observers or observed models are modified by plugins.
161
+
162
+ load_observers
163
+ end
164
+
165
+ # Check for valid Ruby version
166
+ # This is done in an external file, so we can use it
167
+ # from the `rails` program as well without duplication.
168
+ def check_ruby_version
169
+ require 'ruby_version_check'
170
+ end
171
+
172
+ # If Rails is vendored and RubyGems is available, install stub GemSpecs
173
+ # for Rails, Active Support, Active Record, Action Pack, Action Mailer, and
174
+ # Active Resource. This allows Gem plugins to depend on Rails even when
175
+ # the Gem version of Rails shouldn't be loaded.
176
+ def install_gem_spec_stubs
177
+ unless Rails.respond_to?(:vendor_rails?)
178
+ abort %{Your config/boot.rb is outdated: Run "rake rails:update".}
179
+ end
180
+
181
+ if Rails.vendor_rails?
182
+ begin; require "rubygems"; rescue LoadError; return; end
183
+
184
+ stubs = %w(erails activesupport activerecord eactionpack actionmailer activeresource)
185
+ stubs.reject! { |s| Gem.loaded_specs.key?(s) }
186
+
187
+ stubs.each do |stub|
188
+ Gem.loaded_specs[stub] = Gem::Specification.new do |s|
189
+ s.name = stub
190
+ s.version = Rails::VERSION::STRING
191
+ end
192
+ end
193
+ end
194
+ end
195
+
196
+ # Set the <tt>$LOAD_PATH</tt> based on the value of
197
+ # Configuration#load_paths. Duplicates are removed.
198
+ def set_load_path
199
+ load_paths = configuration.load_paths + configuration.framework_paths
200
+ load_paths.reverse_each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) }
201
+ $LOAD_PATH.uniq!
202
+ end
203
+
204
+ # Set the paths from which Rails will automatically load source files, and
205
+ # the load_once paths.
206
+ def set_autoload_paths
207
+ ActiveSupport::Dependencies.load_paths = configuration.load_paths.uniq
208
+ ActiveSupport::Dependencies.load_once_paths = configuration.load_once_paths.uniq
209
+
210
+ extra = ActiveSupport::Dependencies.load_once_paths - ActiveSupport::Dependencies.load_paths
211
+ unless extra.empty?
212
+ abort <<-end_error
213
+ load_once_paths must be a subset of the load_paths.
214
+ Extra items in load_once_paths: #{extra * ','}
215
+ end_error
216
+ end
217
+
218
+ # Freeze the arrays so future modifications will fail rather than do nothing mysteriously
219
+ configuration.load_once_paths.freeze
220
+ end
221
+
222
+ # Requires all frameworks specified by the Configuration#frameworks
223
+ # list. By default, all frameworks (Active Record, Active Support,
224
+ # Action Pack, Action Mailer, and Active Resource) are loaded.
225
+ def require_frameworks
226
+ configuration.frameworks.each { |framework| require(framework.to_s) }
227
+ rescue LoadError => e
228
+ # re-raise because Mongrel would swallow it
229
+ raise e.to_s
230
+ end
231
+
232
+ # Add the load paths used by support functions such as the info controller
233
+ def add_support_load_paths
234
+ end
235
+
236
+ # Adds all load paths from plugins to the global set of load paths, so that
237
+ # code from plugins can be required (explicitly or automatically via ActiveSupport::Dependencies).
238
+ def add_plugin_load_paths
239
+ plugin_loader.add_plugin_load_paths
240
+ end
241
+
242
+ def add_gem_load_paths
243
+ unless @configuration.gems.empty?
244
+ require "rubygems"
245
+ @configuration.gems.each { |gem| gem.add_load_paths }
246
+ end
247
+ end
248
+
249
+ def load_gems
250
+ @configuration.gems.each { |gem| gem.load }
251
+ end
252
+
253
+ def check_gem_dependencies
254
+ unloaded_gems = @configuration.gems.reject { |g| g.loaded? }
255
+ if unloaded_gems.size > 0
256
+ @gems_dependencies_loaded = false
257
+ # don't print if the gems rake tasks are being run
258
+ unless $rails_gem_installer
259
+ abort <<-end_error
260
+ Missing these required gems:
261
+ #{unloaded_gems.map { |gem| "#{gem.name} #{gem.requirement}" } * "\n "}
262
+
263
+ You're running:
264
+ ruby #{Gem.ruby_version} at #{Gem.ruby}
265
+ rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
266
+
267
+ Run `rake gems:install` to install the missing gems.
268
+ end_error
269
+ end
270
+ else
271
+ @gems_dependencies_loaded = true
272
+ end
273
+ end
274
+
275
+ # Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
276
+ # defaults to <tt>vendor/plugins</tt> but may also be set to a list of
277
+ # paths, such as
278
+ # config.plugin_paths = ["#{RAILS_ROOT}/lib/plugins", "#{RAILS_ROOT}/vendor/plugins"]
279
+ #
280
+ # In the default implementation, as each plugin discovered in <tt>plugin_paths</tt> is initialized:
281
+ # * its +lib+ directory, if present, is added to the load path (immediately after the applications lib directory)
282
+ # * <tt>init.rb</tt> is evaluated, if present
283
+ #
284
+ # After all plugins are loaded, duplicates are removed from the load path.
285
+ # If an array of plugin names is specified in config.plugins, only those plugins will be loaded
286
+ # and they plugins will be loaded in that order. Otherwise, plugins are loaded in alphabetical
287
+ # order.
288
+ #
289
+ # if config.plugins ends contains :all then the named plugins will be loaded in the given order and all other
290
+ # plugins will be loaded in alphabetical order
291
+ def load_plugins
292
+ plugin_loader.load_plugins
293
+ end
294
+
295
+ def plugin_loader
296
+ @plugin_loader ||= configuration.plugin_loader.new(self)
297
+ end
298
+
299
+ # Loads the environment specified by Configuration#environment_path, which
300
+ # is typically one of development, test, or production.
301
+ def load_environment
302
+ silence_warnings do
303
+ return if @environment_loaded
304
+ @environment_loaded = true
305
+
306
+ config = configuration
307
+ constants = self.class.constants
308
+
309
+ eval(IO.read(configuration.environment_path), binding, configuration.environment_path)
310
+
311
+ (self.class.constants - constants).each do |const|
312
+ Object.const_set(const, self.class.const_get(const))
313
+ end
314
+ end
315
+ end
316
+
317
+ def load_observers
318
+ if gems_dependencies_loaded && configuration.frameworks.include?(:active_record)
319
+ ActiveRecord::Base.instantiate_observers
320
+ end
321
+ end
322
+
323
+ # For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the
324
+ # multibyte safe operations. Plugin authors supporting other encodings
325
+ # should override this behaviour and set the relevant +default_charset+
326
+ # on ActionController::Base.
327
+ #
328
+ # For Ruby 1.9, this does nothing. Specify the default encoding in the Ruby
329
+ # shebang line if you don't want UTF-8.
330
+ def initialize_encoding
331
+ $KCODE='u' if RUBY_VERSION < '1.9'
332
+ end
333
+
334
+ # This initialization routine does nothing unless <tt>:active_record</tt>
335
+ # is one of the frameworks to load (Configuration#frameworks). If it is,
336
+ # this sets the database configuration from Configuration#database_configuration
337
+ # and then establishes the connection.
338
+ def initialize_database
339
+ if configuration.frameworks.include?(:active_record)
340
+ ActiveRecord::Base.configurations = configuration.database_configuration
341
+ ActiveRecord::Base.establish_connection
342
+ end
343
+ end
344
+
345
+ def initialize_cache
346
+ unless defined?(RAILS_CACHE)
347
+ silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(configuration.cache_store) }
348
+ end
349
+ end
350
+
351
+ def initialize_framework_caches
352
+ if configuration.frameworks.include?(:action_controller)
353
+ ActionController::Base.cache_store ||= RAILS_CACHE
354
+ end
355
+ end
356
+
357
+ # If the RAILS_DEFAULT_LOGGER constant is already set, this initialization
358
+ # routine does nothing. If the constant is not set, and Configuration#logger
359
+ # is not +nil+, this also does nothing. Otherwise, a new logger instance
360
+ # is created at Configuration#log_path, with a default log level of
361
+ # Configuration#log_level.
362
+ #
363
+ # If the log could not be created, the log will be set to output to
364
+ # +STDERR+, with a log level of +WARN+.
365
+ def initialize_logger
366
+ # if the environment has explicitly defined a logger, use it
367
+ return if defined?(RAILS_DEFAULT_LOGGER)
368
+
369
+ unless logger = configuration.logger
370
+ begin
371
+ logger = ActiveSupport::BufferedLogger.new(configuration.log_path)
372
+ logger.level = ActiveSupport::BufferedLogger.const_get(configuration.log_level.to_s.upcase)
373
+ if configuration.environment == "production"
374
+ logger.auto_flushing = false
375
+ logger.set_non_blocking_io
376
+ end
377
+ rescue StandardError => e
378
+ logger = ActiveSupport::BufferedLogger.new(STDERR)
379
+ logger.level = ActiveSupport::BufferedLogger::WARN
380
+ logger.warn(
381
+ "Enhanced Rails Error: Unable to access log file. Please ensure that #{configuration.log_path} exists and is chmod 0666. " +
382
+ "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
383
+ )
384
+ end
385
+ end
386
+
387
+ silence_warnings { Object.const_set "RAILS_DEFAULT_LOGGER", logger }
388
+ end
389
+
390
+ # Sets the logger for Active Record, Action Controller, and Action Mailer
391
+ # (but only for those frameworks that are to be loaded). If the framework's
392
+ # logger is already set, it is not changed, otherwise it is set to use
393
+ # RAILS_DEFAULT_LOGGER.
394
+ def initialize_framework_logging
395
+ for framework in ([ :active_record, :action_controller, :action_mailer ] & configuration.frameworks)
396
+ framework.to_s.camelize.constantize.const_get("Base").logger ||= RAILS_DEFAULT_LOGGER
397
+ end
398
+
399
+ RAILS_CACHE.logger ||= RAILS_DEFAULT_LOGGER
400
+ end
401
+
402
+ # Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+
403
+ # (but only for those frameworks that are to be loaded). If the framework's
404
+ # paths have already been set, it is not changed, otherwise it is
405
+ # set to use Configuration#view_path.
406
+ def initialize_framework_views
407
+ ActionMailer::Base.template_root ||= configuration.view_path if configuration.frameworks.include?(:action_mailer)
408
+ ActionController::Base.view_paths = [configuration.view_path] if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty?
409
+ end
410
+
411
+ # If Action Controller is not one of the loaded frameworks (Configuration#frameworks)
412
+ # this does nothing. Otherwise, it loads the routing definitions and sets up
413
+ # loading module used to lazily load controllers (Configuration#controller_paths).
414
+ def initialize_routing
415
+ return unless configuration.frameworks.include?(:action_controller)
416
+ ActionController::Routing.controller_paths = configuration.controller_paths
417
+ ActionController::Routing::Routes.configuration_file = configuration.routes_configuration_file
418
+ ActionController::Routing::Routes.reload
419
+ end
420
+
421
+ # Sets the dependency loading mechanism based on the value of
422
+ # Configuration#cache_classes.
423
+ def initialize_dependency_mechanism
424
+ ActiveSupport::Dependencies.mechanism = configuration.cache_classes ? :require : :load
425
+ end
426
+
427
+ # Loads support for "whiny nil" (noisy warnings when methods are invoked
428
+ # on +nil+ values) if Configuration#whiny_nils is true.
429
+ def initialize_whiny_nils
430
+ require('active_support/whiny_nil') if configuration.whiny_nils
431
+ end
432
+
433
+ def initialize_temporary_session_directory
434
+ if configuration.frameworks.include?(:action_controller)
435
+ session_path = "#{configuration.root_path}/tmp/sessions/"
436
+ ActionController::Base.session_options[:tmpdir] = File.exist?(session_path) ? session_path : Dir::tmpdir
437
+ end
438
+ end
439
+
440
+ # Sets the default value for Time.zone, and turns on ActiveRecord::Base#time_zone_aware_attributes.
441
+ # If assigned value cannot be matched to a TimeZone, an exception will be raised.
442
+ def initialize_time_zone
443
+ if configuration.time_zone
444
+ zone_default = Time.send!(:get_zone, configuration.time_zone)
445
+ unless zone_default
446
+ raise %{Value assigned to config.time_zone not recognized. Run "rake -D time" for a list of tasks for finding appropriate time zone names.}
447
+ end
448
+ Time.zone_default = zone_default
449
+ if configuration.frameworks.include?(:active_record)
450
+ ActiveRecord::Base.time_zone_aware_attributes = true
451
+ ActiveRecord::Base.default_timezone = :utc
452
+ end
453
+ end
454
+ end
455
+
456
+ # Initializes framework-specific settings for each of the loaded frameworks
457
+ # (Configuration#frameworks). The available settings map to the accessors
458
+ # on each of the corresponding Base classes.
459
+ def initialize_framework_settings
460
+ configuration.frameworks.each do |framework|
461
+ base_class = framework.to_s.camelize.constantize.const_get("Base")
462
+
463
+ configuration.send(framework).each do |setting, value|
464
+ base_class.send("#{setting}=", value)
465
+ end
466
+ end
467
+ configuration.active_support.each do |setting, value|
468
+ ActiveSupport.send("#{setting}=", value)
469
+ end
470
+ end
471
+
472
+ # Fires the user-supplied after_initialize block (Configuration#after_initialize)
473
+ def after_initialize
474
+ if gems_dependencies_loaded
475
+ configuration.after_initialize_blocks.each do |block|
476
+ block.call
477
+ end
478
+ end
479
+ end
480
+
481
+ def load_application_initializers
482
+ if gems_dependencies_loaded
483
+ Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
484
+ load(initializer)
485
+ end
486
+ end
487
+ end
488
+
489
+ def prepare_dispatcher
490
+ return unless configuration.frameworks.include?(:action_controller)
491
+ require 'dispatcher' unless defined?(::Dispatcher)
492
+ Dispatcher.define_dispatcher_callbacks(configuration.cache_classes)
493
+ Dispatcher.new(RAILS_DEFAULT_LOGGER).send :run_callbacks, :prepare_dispatch
494
+ end
495
+
496
+ end
497
+
498
+ # The Configuration class holds all the parameters for the Initializer and
499
+ # ships with defaults that suites most Rails applications. But it's possible
500
+ # to overwrite everything. Usually, you'll create an Configuration file
501
+ # implicitly through the block running on the Initializer, but it's also
502
+ # possible to create the Configuration instance in advance and pass it in
503
+ # like this:
504
+ #
505
+ # config = Rails::Configuration.new
506
+ # Rails::Initializer.run(:process, config)
507
+ class Configuration
508
+ # The application's base directory.
509
+ attr_reader :root_path
510
+
511
+ # A stub for setting options on ActionController::Base.
512
+ attr_accessor :action_controller
513
+
514
+ # A stub for setting options on ActionMailer::Base.
515
+ attr_accessor :action_mailer
516
+
517
+ # A stub for setting options on ActionView::Base.
518
+ attr_accessor :action_view
519
+
520
+ # A stub for setting options on ActiveRecord::Base.
521
+ attr_accessor :active_record
522
+
523
+ # A stub for setting options on ActiveRecord::Base.
524
+ attr_accessor :active_resource
525
+
526
+ # A stub for setting options on ActiveSupport.
527
+ attr_accessor :active_support
528
+
529
+ # Whether or not classes should be cached (set to false if you want
530
+ # application classes to be reloaded on each request)
531
+ attr_accessor :cache_classes
532
+
533
+ # The list of paths that should be searched for controllers. (Defaults
534
+ # to <tt>app/controllers</tt> and <tt>components</tt>.)
535
+ attr_accessor :controller_paths
536
+
537
+ # The path to the database configuration file to use. (Defaults to
538
+ # <tt>config/database.yml</tt>.)
539
+ attr_accessor :database_configuration_file
540
+
541
+ # The path to the routes configuration file to use. (Defaults to
542
+ # <tt>config/routes.rb</tt>.)
543
+ attr_accessor :routes_configuration_file
544
+
545
+ # The list of rails framework components that should be loaded. (Defaults
546
+ # to <tt>:active_record</tt>, <tt>:action_controller</tt>,
547
+ # <tt>:action_view</tt>, <tt>:action_mailer</tt>, and
548
+ # <tt>:active_resource</tt>).
549
+ attr_accessor :frameworks
550
+
551
+ # An array of additional paths to prepend to the load path. By default,
552
+ # all +app+, +lib+, +vendor+ and mock paths are included in this list.
553
+ attr_accessor :load_paths
554
+
555
+ # An array of paths from which Rails will automatically load from only once.
556
+ # All elements of this array must also be in +load_paths+.
557
+ attr_accessor :load_once_paths
558
+
559
+ # The log level to use for the default Rails logger. In production mode,
560
+ # this defaults to <tt>:info</tt>. In development mode, it defaults to
561
+ # <tt>:debug</tt>.
562
+ attr_accessor :log_level
563
+
564
+ # The path to the log file to use. Defaults to log/#{environment}.log
565
+ # (e.g. log/development.log or log/production.log).
566
+ attr_accessor :log_path
567
+
568
+ # The specific logger to use. By default, a logger will be created and
569
+ # initialized using #log_path and #log_level, but a programmer may
570
+ # specifically set the logger to use via this accessor and it will be
571
+ # used directly.
572
+ attr_accessor :logger
573
+
574
+ # The specific cache store to use. By default, the ActiveSupport::Cache::Store will be used.
575
+ attr_accessor :cache_store
576
+
577
+ # The root of the application's views. (Defaults to <tt>app/views</tt>.)
578
+ attr_accessor :view_path
579
+
580
+ # Set to +true+ if you want to be warned (noisily) when you try to invoke
581
+ # any method of +nil+. Set to +false+ for the standard Ruby behavior.
582
+ attr_accessor :whiny_nils
583
+
584
+ # The list of plugins to load. If this is set to <tt>nil</tt>, all plugins will
585
+ # be loaded. If this is set to <tt>[]</tt>, no plugins will be loaded. Otherwise,
586
+ # plugins will be loaded in the order specified.
587
+ attr_reader :plugins
588
+ def plugins=(plugins)
589
+ @plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym }
590
+ end
591
+
592
+ # The path to the root of the plugins directory. By default, it is in
593
+ # <tt>vendor/plugins</tt>.
594
+ attr_accessor :plugin_paths
595
+
596
+ # The classes that handle finding the desired plugins that you'd like to load for
597
+ # your application. By default it is the Rails::Plugin::FileSystemLocator which finds
598
+ # plugins to load in <tt>vendor/plugins</tt>. You can hook into gem location by subclassing
599
+ # Rails::Plugin::Locator and adding it onto the list of <tt>plugin_locators</tt>.
600
+ attr_accessor :plugin_locators
601
+
602
+ # The class that handles loading each plugin. Defaults to Rails::Plugin::Loader, but
603
+ # a sub class would have access to fine grained modification of the loading behavior. See
604
+ # the implementation of Rails::Plugin::Loader for more details.
605
+ attr_accessor :plugin_loader
606
+
607
+ # Enables or disables plugin reloading. You can get around this setting per plugin.
608
+ # If <tt>reload_plugins?</tt> is false, add this to your plugin's <tt>init.rb</tt>
609
+ # to make it reloadable:
610
+ #
611
+ # ActiveSupport::Dependencies.load_once_paths.delete lib_path
612
+ #
613
+ # If <tt>reload_plugins?</tt> is true, add this to your plugin's <tt>init.rb</tt>
614
+ # to only load it once:
615
+ #
616
+ # ActiveSupport::Dependencies.load_once_paths << lib_path
617
+ #
618
+ attr_accessor :reload_plugins
619
+
620
+ # Returns true if plugin reloading is enabled.
621
+ def reload_plugins?
622
+ !!@reload_plugins
623
+ end
624
+
625
+ # Default Template Engine to use <tt>erb</tt> or <tt>haml</tt>
626
+ # If you use haml, will be added a gem dependency, so you can do
627
+ #
628
+ # rake gems:install
629
+ #
630
+ # For install it!
631
+ attr_reader :template_engine
632
+ def template_engine=(engine)
633
+ @gems << Rails::GemDependency.new(engine.to_s) if engine.to_sym == :haml
634
+ end
635
+
636
+ # An array of gems that this rails application depends on. Rails will automatically load
637
+ # these gems during installation, and allow you to install any missing gems with:
638
+ #
639
+ # rake gems:install
640
+ #
641
+ # You can add gems with the #gem method.
642
+ attr_accessor :gems
643
+
644
+ # Adds a single Gem dependency to the rails application. By default, it will require
645
+ # the library with the same name as the gem. Use :lib to specify a different name.
646
+ #
647
+ # # gem 'aws-s3', '>= 0.4.0'
648
+ # # require 'aws/s3'
649
+ # config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
650
+ # :source => "http://code.whytheluckystiff.net"
651
+ #
652
+ # To require a library be installed, but not attempt to load it, pass :lib => false
653
+ #
654
+ # config.gem 'qrp', :version => '0.4.1', :lib => false
655
+ def gem(name, options = {})
656
+ @gems << Rails::GemDependency.new(name, options)
657
+ end
658
+
659
+ # Deprecated options:
660
+ def breakpoint_server(_ = nil)
661
+ $stderr.puts %(
662
+ *******************************************************************
663
+ * config.breakpoint_server has been deprecated and has no effect. *
664
+ *******************************************************************
665
+ )
666
+ end
667
+ alias_method :breakpoint_server=, :breakpoint_server
668
+
669
+ # Sets the default +time_zone+. Setting this will enable +time_zone+
670
+ # awareness for Active Record models and set the Active Record default
671
+ # timezone to <tt>:utc</tt>.
672
+ attr_accessor :time_zone
673
+
674
+ # Create a new Configuration instance, initialized with the default
675
+ # values.
676
+ def initialize
677
+ set_root_path!
678
+
679
+ self.frameworks = default_frameworks
680
+ self.load_paths = default_load_paths
681
+ self.load_once_paths = default_load_once_paths
682
+ self.log_path = default_log_path
683
+ self.log_level = default_log_level
684
+ self.view_path = default_view_path
685
+ self.controller_paths = default_controller_paths
686
+ self.cache_classes = default_cache_classes
687
+ self.whiny_nils = default_whiny_nils
688
+ self.plugins = default_plugins
689
+ self.plugin_paths = default_plugin_paths
690
+ self.plugin_locators = default_plugin_locators
691
+ self.plugin_loader = default_plugin_loader
692
+ self.database_configuration_file = default_database_configuration_file
693
+ self.routes_configuration_file = default_routes_configuration_file
694
+ self.gems = default_gems
695
+
696
+ for framework in default_frameworks
697
+ self.send("#{framework}=", Rails::OrderedOptions.new)
698
+ end
699
+ self.active_support = Rails::OrderedOptions.new
700
+ end
701
+
702
+ # Set the root_path to RAILS_ROOT and canonicalize it.
703
+ def set_root_path!
704
+ raise 'RAILS_ROOT is not set' unless defined?(::RAILS_ROOT)
705
+ raise 'RAILS_ROOT is not a directory' unless File.directory?(::RAILS_ROOT)
706
+
707
+ @root_path =
708
+ # Pathname is incompatible with Windows, but Windows doesn't have
709
+ # real symlinks so File.expand_path is safe.
710
+ if RUBY_PLATFORM =~ /(:?mswin|mingw)/
711
+ File.expand_path(::RAILS_ROOT)
712
+
713
+ # Otherwise use Pathname#realpath which respects symlinks.
714
+ else
715
+ Pathname.new(::RAILS_ROOT).realpath.to_s
716
+ end
717
+
718
+ Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT)
719
+ ::RAILS_ROOT.replace @root_path
720
+ end
721
+
722
+ # Loads and returns the contents of the #database_configuration_file. The
723
+ # contents of the file are processed via ERB before being sent through
724
+ # YAML::load.
725
+ def database_configuration
726
+ require 'erb'
727
+ YAML::load(ERB.new(IO.read(database_configuration_file)).result)
728
+ end
729
+
730
+ # The path to the current environment's file (<tt>development.rb</tt>, etc.). By
731
+ # default the file is at <tt>config/environments/#{environment}.rb</tt>.
732
+ def environment_path
733
+ "#{root_path}/config/environments/#{environment}.rb"
734
+ end
735
+
736
+ # Return the currently selected environment. By default, it returns the
737
+ # value of the RAILS_ENV constant.
738
+ def environment
739
+ ::RAILS_ENV
740
+ end
741
+
742
+ # Adds a block which will be executed after rails has been fully initialized.
743
+ # Useful for per-environment configuration which depends on the framework being
744
+ # fully initialized.
745
+ def after_initialize(&after_initialize_block)
746
+ after_initialize_blocks << after_initialize_block if after_initialize_block
747
+ end
748
+
749
+ # Returns the blocks added with Configuration#after_initialize
750
+ def after_initialize_blocks
751
+ @after_initialize_blocks ||= []
752
+ end
753
+
754
+ # Add a preparation callback that will run before every request in development
755
+ # mode, or before the first request in production.
756
+ #
757
+ # See Dispatcher#to_prepare.
758
+ def to_prepare(&callback)
759
+ after_initialize do
760
+ require 'dispatcher' unless defined?(::Dispatcher)
761
+ Dispatcher.to_prepare(&callback)
762
+ end
763
+ end
764
+
765
+ def builtin_directories
766
+ # Include builtins only in the development environment.
767
+ (environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
768
+ end
769
+
770
+ def framework_paths
771
+ paths = %w(erailties erailties/lib activesupport/lib)
772
+ paths << 'eactionpack/lib' if frameworks.include? :action_controller or frameworks.include? :action_view
773
+
774
+ [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
775
+ paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include? framework
776
+ end
777
+
778
+ paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
779
+ end
780
+
781
+ private
782
+ def framework_root_path
783
+ defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/erails"
784
+ end
785
+
786
+ def default_frameworks
787
+ [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
788
+ end
789
+
790
+ def default_load_paths
791
+ paths = []
792
+
793
+ # Add the old mock paths only if the directories exists
794
+ paths.concat(Dir["#{root_path}/test/mocks/#{environment}"]) if File.exists?("#{root_path}/test/mocks/#{environment}")
795
+
796
+ # Add the app's controller directory
797
+ paths.concat(Dir["#{root_path}/app/controllers/"])
798
+
799
+ # Then components subdirectories.
800
+ paths.concat(Dir["#{root_path}/components/[_a-z]*"])
801
+
802
+ # Followed by the standard includes.
803
+ paths.concat %w(
804
+ app
805
+ app/models
806
+ app/controllers
807
+ app/helpers
808
+ app/services
809
+ components
810
+ config
811
+ lib
812
+ vendor
813
+ ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
814
+
815
+ paths.concat builtin_directories
816
+ end
817
+
818
+ # Doesn't matter since plugins aren't in load_paths yet.
819
+ def default_load_once_paths
820
+ []
821
+ end
822
+
823
+ def default_log_path
824
+ File.join(root_path, 'log', "#{environment}.log")
825
+ end
826
+
827
+ def default_log_level
828
+ environment == 'production' ? :info : :debug
829
+ end
830
+
831
+ def default_database_configuration_file
832
+ File.join(root_path, 'config', 'database.yml')
833
+ end
834
+
835
+ def default_routes_configuration_file
836
+ File.join(root_path, 'config', 'routes.rb')
837
+ end
838
+
839
+ def default_view_path
840
+ File.join(root_path, 'app', 'views')
841
+ end
842
+
843
+ def default_controller_paths
844
+ paths = [File.join(root_path, 'app', 'controllers')]
845
+ paths.concat builtin_directories
846
+ paths
847
+ end
848
+
849
+ def default_dependency_mechanism
850
+ :load
851
+ end
852
+
853
+ def default_cache_classes
854
+ false
855
+ end
856
+
857
+ def default_whiny_nils
858
+ false
859
+ end
860
+
861
+ def default_plugins
862
+ nil
863
+ end
864
+
865
+ def default_plugin_paths
866
+ ["#{root_path}/vendor/plugins"]
867
+ end
868
+
869
+ def default_plugin_locators
870
+ locators = []
871
+ locators << Plugin::GemLocator if defined? Gem
872
+ locators << Plugin::FileSystemLocator
873
+ end
874
+
875
+ def default_plugin_loader
876
+ Plugin::Loader
877
+ end
878
+
879
+ def default_cache_store
880
+ if File.exist?("#{root_path}/tmp/cache/")
881
+ [ :file_store, "#{root_path}/tmp/cache/" ]
882
+ else
883
+ :memory_store
884
+ end
885
+ end
886
+
887
+ def default_gems
888
+ []
889
+ end
890
+ end
891
+ end
892
+
893
+ # Needs to be duplicated from Active Support since its needed before Active
894
+ # Support is available. Here both Options and Hash are namespaced to prevent
895
+ # conflicts with other implementations AND with the classes residing in Active Support.
896
+ class Rails::OrderedOptions < Array #:nodoc:
897
+ def []=(key, value)
898
+ key = key.to_sym
899
+
900
+ if pair = find_pair(key)
901
+ pair.pop
902
+ pair << value
903
+ else
904
+ self << [key, value]
905
+ end
906
+ end
907
+
908
+ def [](key)
909
+ pair = find_pair(key.to_sym)
910
+ pair ? pair.last : nil
911
+ end
912
+
913
+ def method_missing(name, *args)
914
+ if name.to_s =~ /(.*)=$/
915
+ self[$1.to_sym] = args.first
916
+ else
917
+ self[name]
918
+ end
919
+ end
920
+
921
+ private
922
+ def find_pair(key)
923
+ self.each { |i| return i if i.first == key }
924
+ return false
925
+ end
926
+ end