rails 1.0.0 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rails might be problematic. Click here for more details.

Files changed (156) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +103 -0
  3. metadata +228 -294
  4. data/CHANGELOG +0 -865
  5. data/MIT-LICENSE +0 -20
  6. data/README +0 -153
  7. data/Rakefile +0 -422
  8. data/bin/about +0 -3
  9. data/bin/breakpointer +0 -3
  10. data/bin/console +0 -3
  11. data/bin/destroy +0 -3
  12. data/bin/generate +0 -3
  13. data/bin/performance/benchmarker +0 -3
  14. data/bin/performance/profiler +0 -3
  15. data/bin/plugin +0 -3
  16. data/bin/process/reaper +0 -3
  17. data/bin/process/spawner +0 -3
  18. data/bin/process/spinner +0 -3
  19. data/bin/rails +0 -21
  20. data/bin/runner +0 -3
  21. data/bin/server +0 -3
  22. data/builtin/controllers/rails_info_controller.rb +0 -11
  23. data/configs/apache.conf +0 -40
  24. data/configs/database.yml +0 -85
  25. data/configs/empty.log +0 -0
  26. data/configs/lighttpd.conf +0 -40
  27. data/configs/routes.rb +0 -19
  28. data/dispatches/dispatch.fcgi +0 -24
  29. data/dispatches/dispatch.rb +0 -10
  30. data/dispatches/gateway.cgi +0 -97
  31. data/doc/README_FOR_APP +0 -2
  32. data/environments/boot.rb +0 -19
  33. data/environments/development.rb +0 -19
  34. data/environments/environment.rb +0 -53
  35. data/environments/production.rb +0 -19
  36. data/environments/test.rb +0 -19
  37. data/fresh_rakefile +0 -10
  38. data/helpers/application.rb +0 -4
  39. data/helpers/application_helper.rb +0 -3
  40. data/helpers/test_helper.rb +0 -28
  41. data/html/404.html +0 -8
  42. data/html/500.html +0 -8
  43. data/html/favicon.ico +0 -0
  44. data/html/images/rails.png +0 -0
  45. data/html/index.html +0 -277
  46. data/html/javascripts/controls.js +0 -750
  47. data/html/javascripts/dragdrop.js +0 -584
  48. data/html/javascripts/effects.js +0 -854
  49. data/html/javascripts/prototype.js +0 -1785
  50. data/html/robots.txt +0 -1
  51. data/lib/binding_of_caller.rb +0 -85
  52. data/lib/breakpoint.rb +0 -523
  53. data/lib/breakpoint_client.rb +0 -196
  54. data/lib/code_statistics.rb +0 -107
  55. data/lib/commands/about.rb +0 -2
  56. data/lib/commands/breakpointer.rb +0 -1
  57. data/lib/commands/console.rb +0 -23
  58. data/lib/commands/destroy.rb +0 -6
  59. data/lib/commands/generate.rb +0 -6
  60. data/lib/commands/ncgi/listener +0 -86
  61. data/lib/commands/ncgi/tracker +0 -69
  62. data/lib/commands/performance/benchmarker.rb +0 -24
  63. data/lib/commands/performance/profiler.rb +0 -34
  64. data/lib/commands/plugin.rb +0 -823
  65. data/lib/commands/process/reaper.rb +0 -130
  66. data/lib/commands/process/spawner.rb +0 -52
  67. data/lib/commands/process/spinner.rb +0 -57
  68. data/lib/commands/runner.rb +0 -27
  69. data/lib/commands/server.rb +0 -28
  70. data/lib/commands/servers/lighttpd.rb +0 -60
  71. data/lib/commands/servers/webrick.rb +0 -59
  72. data/lib/commands/update.rb +0 -4
  73. data/lib/commands.rb +0 -17
  74. data/lib/console_sandbox.rb +0 -6
  75. data/lib/dispatcher.rb +0 -99
  76. data/lib/fcgi_handler.rb +0 -189
  77. data/lib/initializer.rb +0 -553
  78. data/lib/rails_generator/base.rb +0 -203
  79. data/lib/rails_generator/commands.rb +0 -509
  80. data/lib/rails_generator/generators/applications/app/USAGE +0 -16
  81. data/lib/rails_generator/generators/applications/app/app_generator.rb +0 -140
  82. data/lib/rails_generator/generators/components/controller/USAGE +0 -30
  83. data/lib/rails_generator/generators/components/controller/controller_generator.rb +0 -38
  84. data/lib/rails_generator/generators/components/controller/templates/controller.rb +0 -10
  85. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +0 -18
  86. data/lib/rails_generator/generators/components/controller/templates/helper.rb +0 -2
  87. data/lib/rails_generator/generators/components/controller/templates/view.rhtml +0 -2
  88. data/lib/rails_generator/generators/components/mailer/USAGE +0 -18
  89. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +0 -32
  90. data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -3
  91. data/lib/rails_generator/generators/components/mailer/templates/mailer.rb +0 -13
  92. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +0 -37
  93. data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -3
  94. data/lib/rails_generator/generators/components/migration/USAGE +0 -14
  95. data/lib/rails_generator/generators/components/migration/migration_generator.rb +0 -7
  96. data/lib/rails_generator/generators/components/migration/templates/migration.rb +0 -7
  97. data/lib/rails_generator/generators/components/model/USAGE +0 -17
  98. data/lib/rails_generator/generators/components/model/model_generator.rb +0 -18
  99. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +0 -5
  100. data/lib/rails_generator/generators/components/model/templates/model.rb +0 -2
  101. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +0 -10
  102. data/lib/rails_generator/generators/components/plugin/USAGE +0 -33
  103. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +0 -33
  104. data/lib/rails_generator/generators/components/plugin/templates/README +0 -4
  105. data/lib/rails_generator/generators/components/plugin/templates/Rakefile +0 -22
  106. data/lib/rails_generator/generators/components/plugin/templates/USAGE +0 -8
  107. data/lib/rails_generator/generators/components/plugin/templates/generator.rb +0 -8
  108. data/lib/rails_generator/generators/components/plugin/templates/init.rb +0 -1
  109. data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +0 -1
  110. data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +0 -4
  111. data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +0 -8
  112. data/lib/rails_generator/generators/components/scaffold/USAGE +0 -32
  113. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +0 -184
  114. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +0 -54
  115. data/lib/rails_generator/generators/components/scaffold/templates/form.rhtml +0 -3
  116. data/lib/rails_generator/generators/components/scaffold/templates/form_scaffolding.rhtml +0 -1
  117. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +0 -98
  118. data/lib/rails_generator/generators/components/scaffold/templates/helper.rb +0 -2
  119. data/lib/rails_generator/generators/components/scaffold/templates/layout.rhtml +0 -13
  120. data/lib/rails_generator/generators/components/scaffold/templates/style.css +0 -74
  121. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.rhtml +0 -9
  122. data/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +0 -27
  123. data/lib/rails_generator/generators/components/scaffold/templates/view_new.rhtml +0 -8
  124. data/lib/rails_generator/generators/components/scaffold/templates/view_show.rhtml +0 -8
  125. data/lib/rails_generator/generators/components/session_migration/USAGE +0 -15
  126. data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +0 -12
  127. data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +0 -15
  128. data/lib/rails_generator/generators/components/web_service/USAGE +0 -28
  129. data/lib/rails_generator/generators/components/web_service/templates/api_definition.rb +0 -5
  130. data/lib/rails_generator/generators/components/web_service/templates/controller.rb +0 -8
  131. data/lib/rails_generator/generators/components/web_service/templates/functional_test.rb +0 -19
  132. data/lib/rails_generator/generators/components/web_service/web_service_generator.rb +0 -29
  133. data/lib/rails_generator/lookup.rb +0 -210
  134. data/lib/rails_generator/manifest.rb +0 -53
  135. data/lib/rails_generator/options.rb +0 -140
  136. data/lib/rails_generator/scripts/destroy.rb +0 -7
  137. data/lib/rails_generator/scripts/generate.rb +0 -7
  138. data/lib/rails_generator/scripts/update.rb +0 -12
  139. data/lib/rails_generator/scripts.rb +0 -83
  140. data/lib/rails_generator/simple_logger.rb +0 -46
  141. data/lib/rails_generator/spec.rb +0 -44
  142. data/lib/rails_generator.rb +0 -43
  143. data/lib/rails_info.rb +0 -104
  144. data/lib/rails_version.rb +0 -9
  145. data/lib/railties_path.rb +0 -1
  146. data/lib/rubyprof_ext.rb +0 -35
  147. data/lib/tasks/databases.rake +0 -158
  148. data/lib/tasks/documentation.rake +0 -76
  149. data/lib/tasks/framework.rake +0 -71
  150. data/lib/tasks/javascripts.rake +0 -6
  151. data/lib/tasks/misc.rake +0 -19
  152. data/lib/tasks/rails.rb +0 -8
  153. data/lib/tasks/statistics.rake +0 -16
  154. data/lib/tasks/testing.rake +0 -50
  155. data/lib/test_help.rb +0 -17
  156. data/lib/webrick_server.rb +0 -170
data/lib/initializer.rb DELETED
@@ -1,553 +0,0 @@
1
- require 'logger'
2
- require 'set'
3
- require File.join(File.dirname(__FILE__), 'railties_path')
4
-
5
- RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
6
-
7
- module Rails
8
- # The Initializer is responsible for processing the Rails configuration, such
9
- # as setting the $LOAD_PATH, requiring the right frameworks, initializing
10
- # logging, and more. It can be run either as a single command that'll just
11
- # use the default configuration, like this:
12
- #
13
- # Rails::Initializer.run
14
- #
15
- # But normally it's more interesting to pass in a custom configuration
16
- # through the block running:
17
- #
18
- # Rails::Initializer.run do |config|
19
- # config.frameworks -= [ :action_web_service ]
20
- # end
21
- #
22
- # This will use the default configuration options from Rails::Configuration,
23
- # but allow for overwriting on select areas.
24
- class Initializer
25
- # The Configuration instance used by this Initializer instance.
26
- attr_reader :configuration
27
-
28
- # The set of loaded plugins.
29
- attr_reader :loaded_plugins
30
-
31
- # Runs the initializer. By default, this will invoke the #process method,
32
- # which simply executes all of the initialization routines. Alternately,
33
- # you can specify explicitly which initialization routine you want:
34
- #
35
- # Rails::Initializer.run(:set_load_path)
36
- #
37
- # This is useful if you only want the load path initialized, without
38
- # incuring the overhead of completely loading the entire environment.
39
- def self.run(command = :process, configuration = Configuration.new)
40
- yield configuration if block_given?
41
- initializer = new configuration
42
- initializer.send(command)
43
- initializer
44
- end
45
-
46
- # Create a new Initializer instance that references the given Configuration
47
- # instance.
48
- def initialize(configuration)
49
- @configuration = configuration
50
- @loaded_plugins = Set.new
51
- end
52
-
53
- # Sequentially step through all of the available initialization routines,
54
- # in order:
55
- #
56
- # * #set_load_path
57
- # * #set_connection_adapters
58
- # * #require_frameworks
59
- # * #load_environment
60
- # * #initialize_database
61
- # * #initialize_logger
62
- # * #initialize_framework_logging
63
- # * #initialize_framework_views
64
- # * #initialize_routing
65
- # * #initialize_dependency_mechanism
66
- # * #initialize_breakpoints
67
- # * #initialize_whiny_nils
68
- # * #initialize_framework_settings
69
- # * #load_environment
70
- # * #load_plugins
71
- #
72
- # (Note that #load_environment is invoked twice, once at the start and
73
- # once at the end, to support the legacy configuration style where the
74
- # environment could overwrite the defaults directly, instead of via the
75
- # Configuration instance.
76
- def process
77
- set_load_path
78
- set_connection_adapters
79
-
80
- require_frameworks
81
- load_environment
82
-
83
- initialize_database
84
- initialize_logger
85
- initialize_framework_logging
86
- initialize_framework_views
87
- initialize_dependency_mechanism
88
- initialize_breakpoints
89
- initialize_whiny_nils
90
-
91
- initialize_framework_settings
92
-
93
- # Support for legacy configuration style where the environment
94
- # could overwrite anything set from the defaults/global through
95
- # the individual base class configurations.
96
- load_environment
97
-
98
- load_framework_info
99
-
100
- load_plugins
101
-
102
- # Routing must be initialized after plugins to allow the former to extend the routes
103
- initialize_routing
104
- end
105
-
106
- # Set the <tt>$LOAD_PATH</tt> based on the value of
107
- # Configuration#load_paths. Duplicates are removed.
108
- def set_load_path
109
- configuration.load_paths.reverse.each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) }
110
- $LOAD_PATH.uniq!
111
- end
112
-
113
- # Sets the +RAILS_CONNECTION_ADAPTERS+ constant based on the value of
114
- # Configuration#connection_adapters. This constant is used to determine
115
- # which database adapters should be loaded (by default, all adapters are
116
- # loaded).
117
- def set_connection_adapters
118
- Object.const_set("RAILS_CONNECTION_ADAPTERS", configuration.connection_adapters) if configuration.connection_adapters
119
- end
120
-
121
- # Requires all frameworks specified by the Configuration#frameworks
122
- # list. By default, all frameworks (ActiveRecord, ActiveSupport,
123
- # ActionPack, ActionMailer, and ActionWebService) are loaded.
124
- def require_frameworks
125
- configuration.frameworks.each { |framework| require(framework.to_s) }
126
- end
127
-
128
- # Loads Rails::VERSION and Rails::Info.
129
- # TODO: Make this work via dependencies.rb/const_missing instead.
130
- def load_framework_info
131
- require 'rails_info'
132
- end
133
-
134
- # Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
135
- # defaults to <tt>vendor/plugins</tt> but may also be set to a list of
136
- # paths, such as
137
- # config.plugin_paths = ['lib/plugins', 'vendor/plugins']
138
- #
139
- # Each plugin discovered in <tt>plugin_paths</tt> is initialized:
140
- # * add its +lib+ directory, if present, to the beginning of the load path
141
- # * evaluate <tt>init.rb</tt> if present
142
- #
143
- # After all plugins are loaded, duplicates are removed from the load path.
144
- def load_plugins
145
- find_plugins(configuration.plugin_paths).each { |path| load_plugin path }
146
- $LOAD_PATH.uniq!
147
- end
148
-
149
- # Loads the environment specified by Configuration#environment_path, which
150
- # is typically one of development, testing, or production.
151
- def load_environment
152
- silence_warnings do
153
- config = configuration
154
- constants = self.class.constants
155
- eval(IO.read(configuration.environment_path), binding)
156
- (self.class.constants - constants).each do |const|
157
- Object.const_set(const, self.class.const_get(const))
158
- end
159
- end
160
- end
161
-
162
- # This initialization routine does nothing unless <tt>:active_record</tt>
163
- # is one of the frameworks to load (Configuration#frameworks). If it is,
164
- # this sets the database configuration from Configuration#database_configuration
165
- # and then establishes the connection.
166
- def initialize_database
167
- return unless configuration.frameworks.include?(:active_record)
168
- ActiveRecord::Base.configurations = configuration.database_configuration
169
- ActiveRecord::Base.establish_connection
170
- end
171
-
172
- # If the +RAILS_DEFAULT_LOGGER+ constant is already set, this initialization
173
- # routine does nothing. If the constant is not set, and Configuration#logger
174
- # is not +nil+, this also does nothing. Otherwise, a new logger instance
175
- # is created at Configuration#log_path, with a default log level of
176
- # Configuration#log_level.
177
- #
178
- # If the log could not be created, the log will be set to output to
179
- # +STDERR+, with a log level of +WARN+.
180
- def initialize_logger
181
- # if the environment has explicitly defined a logger, use it
182
- return if defined?(RAILS_DEFAULT_LOGGER)
183
-
184
- unless logger = configuration.logger
185
- begin
186
- logger = Logger.new(configuration.log_path)
187
- logger.level = Logger.const_get(configuration.log_level.to_s.upcase)
188
- rescue StandardError
189
- logger = Logger.new(STDERR)
190
- logger.level = Logger::WARN
191
- logger.warn(
192
- "Rails Error: Unable to access log file. Please ensure that #{configuration.log_path} exists and is chmod 0666. " +
193
- "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
194
- )
195
- end
196
- end
197
-
198
- silence_warnings { Object.const_set "RAILS_DEFAULT_LOGGER", logger }
199
- end
200
-
201
- # Sets the logger for ActiveRecord, ActionController, and ActionMailer
202
- # (but only for those frameworks that are to be loaded). If the framework's
203
- # logger is already set, it is not changed, otherwise it is set to use
204
- # +RAILS_DEFAULT_LOGGER+.
205
- def initialize_framework_logging
206
- for framework in ([ :active_record, :action_controller, :action_mailer ] & configuration.frameworks)
207
- framework.to_s.camelize.constantize.const_get("Base").logger ||= RAILS_DEFAULT_LOGGER
208
- end
209
- end
210
-
211
- # Sets the +template_root+ for ActionController::Base and ActionMailer::Base
212
- # (but only for those frameworks that are to be loaded). If the framework's
213
- # +template_root+ has already been set, it is not changed, otherwise it is
214
- # set to use Configuration#view_path.
215
- def initialize_framework_views
216
- for framework in ([ :action_controller, :action_mailer ] & configuration.frameworks)
217
- framework.to_s.camelize.constantize.const_get("Base").template_root ||= configuration.view_path
218
- end
219
- end
220
-
221
- # If ActionController is not one of the loaded frameworks (Configuration#frameworks)
222
- # this does nothing. Otherwise, it loads the routing definitions and sets up
223
- # loading module used to lazily load controllers (Configuration#controller_paths).
224
- def initialize_routing
225
- return unless configuration.frameworks.include?(:action_controller)
226
- ActionController::Routing::Routes.reload
227
- Object.const_set "Controllers", Dependencies::LoadingModule.root(*configuration.controller_paths)
228
- end
229
-
230
- # Sets the dependency loading mechanism based on the value of
231
- # Configuration#cache_classes.
232
- def initialize_dependency_mechanism
233
- Dependencies.mechanism = configuration.cache_classes ? :require : :load
234
- end
235
-
236
- # Sets the +BREAKPOINT_SERVER_PORT+ if Configuration#breakpoint_server
237
- # is true.
238
- def initialize_breakpoints
239
- silence_warnings { Object.const_set("BREAKPOINT_SERVER_PORT", 42531) if configuration.breakpoint_server }
240
- end
241
-
242
- # Loads support for "whiny nil" (noisy warnings when methods are invoked
243
- # on +nil+ values) if Configuration#whiny_nils is true.
244
- def initialize_whiny_nils
245
- require('active_support/whiny_nil') if configuration.whiny_nils
246
- end
247
-
248
- # Initialize framework-specific settings for each of the loaded frameworks
249
- # (Configuration#frameworks). The available settings map to the accessors
250
- # on each of the corresponding Base classes.
251
- def initialize_framework_settings
252
- configuration.frameworks.each do |framework|
253
- base_class = framework.to_s.camelize.constantize.const_get("Base")
254
-
255
- configuration.send(framework).each do |setting, value|
256
- base_class.send("#{setting}=", value)
257
- end
258
- end
259
- end
260
-
261
- protected
262
- # Return a list of plugin paths within base_path. A plugin path is
263
- # a directory that contains either a lib directory or an init.rb file.
264
- # This recurses into directories which are not plugin paths, so you
265
- # may organize your plugins which the plugin path.
266
- def find_plugins(*base_paths)
267
- base_paths.flatten.inject([]) do |plugins, base_path|
268
- Dir.glob(File.join(base_path, '*')).each do |path|
269
- if plugin_path?(path)
270
- plugins << path
271
- elsif File.directory?(path)
272
- plugins += find_plugins(path)
273
- end
274
- end
275
- plugins
276
- end
277
- end
278
-
279
- def plugin_path?(path)
280
- File.directory?(path) and (File.directory?(File.join(path, 'lib')) or File.file?(File.join(path, 'init.rb')))
281
- end
282
-
283
- # Load the plugin at <tt>path</tt> unless already loaded.
284
- #
285
- # Each plugin is initialized:
286
- # * add its +lib+ directory, if present, to the beginning of the load path
287
- # * evaluate <tt>init.rb</tt> if present
288
- #
289
- # Returns <tt>true</tt> if the plugin is successfully loaded or
290
- # <tt>false</tt> if it is already loaded (similar to Kernel#require).
291
- # Raises <tt>LoadError</tt> if the plugin is not found.
292
- def load_plugin(directory)
293
- name = File.basename(directory)
294
- return false if loaded_plugins.include?(name)
295
-
296
- # Catch nonexistent and empty plugins.
297
- raise LoadError, "No such plugin: #{directory}" unless plugin_path?(directory)
298
-
299
- lib_path = File.join(directory, 'lib')
300
- init_path = File.join(directory, 'init.rb')
301
- has_lib = File.directory?(lib_path)
302
- has_init = File.file?(init_path)
303
-
304
- # Add lib to load path.
305
- $LOAD_PATH.unshift(lib_path) if has_lib
306
-
307
- # Allow plugins to reference the current configuration object
308
- config = configuration
309
-
310
- # Evaluate init.rb.
311
- silence_warnings { eval(IO.read(init_path), binding, init_path) } if has_init
312
-
313
- # Add to set of loaded plugins.
314
- loaded_plugins << name
315
- true
316
- end
317
- end
318
-
319
- # The Configuration class holds all the parameters for the Initializer and
320
- # ships with defaults that suites most Rails applications. But it's possible
321
- # to overwrite everything. Usually, you'll create an Configuration file
322
- # implicitly through the block running on the Initializer, but it's also
323
- # possible to create the Configuration instance in advance and pass it in
324
- # like this:
325
- #
326
- # config = Rails::Configuration.new
327
- # Rails::Initializer.run(:process, config)
328
- class Configuration
329
- # A stub for setting options on ActionController::Base
330
- attr_accessor :action_controller
331
-
332
- # A stub for setting options on ActionMailer::Base
333
- attr_accessor :action_mailer
334
-
335
- # A stub for setting options on ActionView::Base
336
- attr_accessor :action_view
337
-
338
- # A stub for setting options on ActionWebService::Base
339
- attr_accessor :action_web_service
340
-
341
- # A stub for setting options on ActiveRecord::Base
342
- attr_accessor :active_record
343
-
344
- # Whether or not to use the breakpoint server (boolean)
345
- attr_accessor :breakpoint_server
346
-
347
- # Whether or not classes should be cached (set to false if you want
348
- # application classes to be reloaded on each request)
349
- attr_accessor :cache_classes
350
-
351
- # The list of connection adapters to load. (By default, all connection
352
- # adapters are loaded. You can set this to be just the adapter(s) you
353
- # will use to reduce your application's load time.)
354
- attr_accessor :connection_adapters
355
-
356
- # The list of paths that should be searched for controllers. (Defaults
357
- # to <tt>app/controllers</tt> and <tt>components</tt>.)
358
- attr_accessor :controller_paths
359
-
360
- # The path to the database configuration file to use. (Defaults to
361
- # <tt>config/database.yml</tt>.)
362
- attr_accessor :database_configuration_file
363
-
364
- # The list of rails framework components that should be loaded. (Defaults
365
- # to <tt>:active_record</tt>, <tt>:action_controller</tt>,
366
- # <tt>:action_view</tt>, <tt>:action_mailer</tt>, and
367
- # <tt>:action_web_service</tt>).
368
- attr_accessor :frameworks
369
-
370
- # An array of additional paths to prepend to the load path. By default,
371
- # all +app+, +lib+, +vendor+ and mock paths are included in this list.
372
- attr_accessor :load_paths
373
-
374
- # The log level to use for the default Rails logger. In production mode,
375
- # this defaults to <tt>:info</tt>. In development mode, it defaults to
376
- # <tt>:debug</tt>.
377
- attr_accessor :log_level
378
-
379
- # The path to the log file to use. Defaults to log/#{environment}.log
380
- # (e.g. log/development.log or log/production.log).
381
- attr_accessor :log_path
382
-
383
- # The specific logger to use. By default, a logger will be created and
384
- # initialized using #log_path and #log_level, but a programmer may
385
- # specifically set the logger to use via this accessor and it will be
386
- # used directly.
387
- attr_accessor :logger
388
-
389
- # The root of the application's views. (Defaults to <tt>app/views</tt>.)
390
- attr_accessor :view_path
391
-
392
- # Set to +true+ if you want to be warned (noisily) when you try to invoke
393
- # any method of +nil+. Set to +false+ for the standard Ruby behavior.
394
- attr_accessor :whiny_nils
395
-
396
- # The path to the root of the plugins directory. By default, it is in
397
- # <tt>vendor/plugins</tt>.
398
- attr_accessor :plugin_paths
399
-
400
- # Create a new Configuration instance, initialized with the default
401
- # values.
402
- def initialize
403
- self.frameworks = default_frameworks
404
- self.load_paths = default_load_paths
405
- self.log_path = default_log_path
406
- self.log_level = default_log_level
407
- self.view_path = default_view_path
408
- self.controller_paths = default_controller_paths
409
- self.cache_classes = default_cache_classes
410
- self.breakpoint_server = default_breakpoint_server
411
- self.whiny_nils = default_whiny_nils
412
- self.plugin_paths = default_plugin_paths
413
- self.database_configuration_file = default_database_configuration_file
414
-
415
- for framework in default_frameworks
416
- self.send("#{framework}=", OrderedOptions.new)
417
- end
418
- end
419
-
420
- # Loads and returns the contents of the #database_configuration_file. The
421
- # contents of the file are processed via ERB before being sent through
422
- # YAML::load.
423
- def database_configuration
424
- YAML::load(ERB.new(IO.read(database_configuration_file)).result)
425
- end
426
-
427
- # The path to the current environment's file (development.rb, etc.). By
428
- # default the file is at <tt>config/environments/#{environment}.rb</tt>.
429
- def environment_path
430
- "#{root_path}/config/environments/#{environment}.rb"
431
- end
432
-
433
- # Return the currently selected environment. By default, it returns the
434
- # value of the +RAILS_ENV+ constant.
435
- def environment
436
- ::RAILS_ENV
437
- end
438
-
439
- private
440
- def root_path
441
- ::RAILS_ROOT
442
- end
443
-
444
- def default_frameworks
445
- [ :active_record, :action_controller, :action_view, :action_mailer, :action_web_service ]
446
- end
447
-
448
- def default_load_paths
449
- paths = ["#{root_path}/test/mocks/#{environment}"]
450
-
451
- # Then model subdirectories.
452
- # TODO: Don't include .rb models as load paths
453
- paths.concat(Dir["#{root_path}/app/models/[_a-z]*"])
454
- paths.concat(Dir["#{root_path}/components/[_a-z]*"])
455
-
456
- # Followed by the standard includes.
457
- # TODO: Don't include dirs for frameworks that are not used
458
- paths.concat %w(
459
- app
460
- app/models
461
- app/controllers
462
- app/helpers
463
- app/services
464
- app/apis
465
- components
466
- config
467
- lib
468
- vendor
469
- vendor/rails/railties
470
- vendor/rails/railties/lib
471
- vendor/rails/actionpack/lib
472
- vendor/rails/activesupport/lib
473
- vendor/rails/activerecord/lib
474
- vendor/rails/actionmailer/lib
475
- vendor/rails/actionwebservice/lib
476
- ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
477
- end
478
-
479
- def default_log_path
480
- File.join(root_path, 'log', "#{environment}.log")
481
- end
482
-
483
- def default_log_level
484
- environment == 'production' ? :info : :debug
485
- end
486
-
487
- def default_database_configuration_file
488
- File.join(root_path, 'config', 'database.yml')
489
- end
490
-
491
- def default_view_path
492
- File.join(root_path, 'app', 'views')
493
- end
494
-
495
- def default_controller_paths
496
- [ File.join(root_path, 'app', 'controllers'), File.join(root_path, 'components'), File.join(RAILTIES_PATH, 'builtin', 'controllers') ]
497
- end
498
-
499
- def default_dependency_mechanism
500
- :load
501
- end
502
-
503
- def default_cache_classes
504
- false
505
- end
506
-
507
- def default_breakpoint_server
508
- false
509
- end
510
-
511
- def default_whiny_nils
512
- false
513
- end
514
-
515
- def default_plugin_paths
516
- ["#{root_path}/vendor/plugins"]
517
- end
518
- end
519
- end
520
-
521
- # Needs to be duplicated from Active Support since its needed before Active
522
- # Support is available.
523
- class OrderedOptions < Array # :nodoc:
524
- def []=(key, value)
525
- key = key.to_sym
526
-
527
- if pair = find_pair(key)
528
- pair.pop
529
- pair << value
530
- else
531
- self << [key, value]
532
- end
533
- end
534
-
535
- def [](key)
536
- pair = find_pair(key.to_sym)
537
- pair ? pair.last : nil
538
- end
539
-
540
- def method_missing(name, *args)
541
- if name.to_s =~ /(.*)=$/
542
- self[$1.to_sym] = args.first
543
- else
544
- self[name]
545
- end
546
- end
547
-
548
- private
549
- def find_pair(key)
550
- self.each { |i| return i if i.first == key }
551
- return false
552
- end
553
- end