rails 1.0.0 → 2.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.
- data/CHANGELOG +1020 -10
- data/MIT-LICENSE +1 -1
- data/README +110 -60
- data/Rakefile +74 -139
- data/bin/about +1 -1
- data/bin/console +1 -1
- data/bin/destroy +1 -1
- data/bin/generate +1 -1
- data/bin/performance/request +3 -0
- data/bin/plugin +1 -1
- data/bin/process/{spinner → inspector} +1 -1
- data/bin/rails +10 -12
- data/bin/runner +1 -1
- data/bin/server +1 -1
- data/{lib/rails_info.rb → builtin/rails_info/rails/info.rb} +33 -14
- data/builtin/rails_info/rails/info_controller.rb +9 -0
- data/builtin/rails_info/rails/info_helper.rb +2 -0
- data/builtin/rails_info/rails_info_controller.rb +2 -0
- data/configs/apache.conf +1 -1
- data/configs/databases/frontbase.yml +28 -0
- data/configs/databases/mysql.yml +54 -0
- data/configs/databases/oracle.yml +39 -0
- data/configs/databases/postgresql.yml +48 -0
- data/configs/databases/sqlite2.yml +16 -0
- data/configs/databases/sqlite3.yml +19 -0
- data/configs/initializers/inflections.rb +10 -0
- data/configs/initializers/mime_types.rb +5 -0
- data/configs/lighttpd.conf +29 -15
- data/configs/routes.rb +27 -11
- data/doc/README_FOR_APP +1 -1
- data/environments/boot.rb +103 -14
- data/environments/development.rb +5 -6
- data/environments/environment.rb +36 -30
- data/environments/production.rb +2 -3
- data/environments/test.rb +5 -2
- data/fresh_rakefile +2 -2
- data/helpers/application.rb +8 -2
- data/helpers/test_helper.rb +10 -0
- data/html/404.html +27 -5
- data/html/422.html +30 -0
- data/html/500.html +27 -5
- data/html/index.html +6 -6
- data/html/javascripts/application.js +2 -0
- data/html/javascripts/controls.js +532 -319
- data/html/javascripts/dragdrop.js +521 -133
- data/html/javascripts/effects.js +708 -442
- data/html/javascripts/prototype.js +3393 -953
- data/html/robots.txt +5 -1
- data/lib/code_statistics.rb +2 -2
- data/lib/commands/console.rb +18 -9
- data/lib/commands/performance/profiler.rb +25 -9
- data/lib/commands/performance/request.rb +6 -0
- data/lib/commands/plugin.rb +196 -96
- data/lib/commands/process/inspector.rb +68 -0
- data/lib/commands/process/reaper.rb +90 -71
- data/lib/commands/process/spawner.rb +188 -21
- data/lib/commands/process/spinner.rb +3 -3
- data/lib/commands/runner.rb +28 -7
- data/lib/commands/server.rb +20 -9
- data/lib/commands/servers/base.rb +31 -0
- data/lib/commands/servers/lighttpd.rb +60 -26
- data/lib/commands/servers/mongrel.rb +69 -0
- data/lib/commands/servers/webrick.rb +18 -11
- data/lib/console_app.rb +30 -0
- data/lib/console_sandbox.rb +2 -2
- data/lib/console_with_helpers.rb +26 -0
- data/lib/dispatcher.rb +3 -78
- data/lib/fcgi_handler.rb +98 -64
- data/lib/initializer.rb +323 -194
- data/lib/rails/plugin/loader.rb +150 -0
- data/lib/rails/plugin/locator.rb +78 -0
- data/lib/rails/plugin.rb +84 -0
- data/lib/{rails_version.rb → rails/version.rb} +1 -1
- data/lib/rails_generator/base.rb +85 -25
- data/lib/rails_generator/commands.rb +122 -40
- data/lib/rails_generator/generated_attribute.rb +42 -0
- data/lib/rails_generator/generators/applications/app/USAGE +0 -7
- data/lib/rails_generator/generators/applications/app/app_generator.rb +67 -28
- data/lib/rails_generator/generators/components/controller/USAGE +11 -12
- data/lib/rails_generator/generators/components/controller/controller_generator.rb +2 -3
- data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +1 -11
- data/lib/rails_generator/generators/components/controller/templates/{view.rhtml → view.html.erb} +0 -0
- data/lib/rails_generator/generators/components/integration_test/USAGE +8 -0
- data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +16 -0
- data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +10 -0
- data/lib/rails_generator/generators/components/mailer/USAGE +9 -11
- data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +10 -8
- data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +3 -0
- data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -3
- data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +9 -25
- data/lib/rails_generator/generators/components/mailer/templates/view.erb +3 -0
- data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -3
- data/lib/rails_generator/generators/components/migration/USAGE +23 -8
- data/lib/rails_generator/generators/components/migration/migration_generator.rb +15 -2
- data/lib/rails_generator/generators/components/migration/templates/migration.rb +7 -3
- data/lib/rails_generator/generators/components/model/USAGE +21 -11
- data/lib/rails_generator/generators/components/model/model_generator.rb +28 -1
- data/lib/rails_generator/generators/components/model/templates/fixtures.yml +18 -4
- data/lib/rails_generator/generators/components/model/templates/migration.rb +16 -0
- data/lib/rails_generator/generators/components/model/templates/unit_test.rb +2 -4
- data/lib/rails_generator/generators/components/observer/USAGE +13 -0
- data/lib/rails_generator/generators/components/observer/observer_generator.rb +16 -0
- data/lib/rails_generator/generators/components/observer/templates/observer.rb +2 -0
- data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +8 -0
- data/lib/rails_generator/generators/components/plugin/USAGE +10 -18
- data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +6 -0
- data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +20 -0
- data/lib/rails_generator/generators/components/plugin/templates/README +10 -1
- data/lib/rails_generator/generators/components/plugin/templates/Rakefile +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/USAGE +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/init.rb +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/install.rb +1 -0
- data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +1 -0
- data/lib/rails_generator/generators/components/resource/USAGE +23 -0
- data/lib/rails_generator/generators/components/resource/resource_generator.rb +74 -0
- data/lib/rails_generator/generators/components/resource/templates/controller.rb +2 -0
- data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +8 -0
- data/lib/rails_generator/generators/components/resource/templates/helper.rb +2 -0
- data/lib/rails_generator/generators/components/scaffold/USAGE +24 -31
- data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +45 -137
- data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +65 -34
- data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +23 -76
- data/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb +17 -0
- data/lib/rails_generator/generators/components/scaffold/templates/style.css +5 -5
- data/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +19 -0
- data/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +24 -0
- data/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +18 -0
- data/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb +10 -0
- data/lib/rails_generator/generators/components/session_migration/USAGE +6 -11
- data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +7 -1
- data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +8 -7
- data/lib/rails_generator/lookup.rb +46 -12
- data/lib/rails_generator/options.rb +11 -8
- data/lib/rails_generator/scripts/destroy.rb +23 -0
- data/lib/rails_generator/scripts.rb +7 -4
- data/lib/rails_generator/secret_key_generator.rb +160 -0
- data/lib/rails_generator/spec.rb +1 -1
- data/lib/rails_generator.rb +1 -1
- data/lib/railties_path.rb +1 -1
- data/lib/ruby_version_check.rb +17 -0
- data/lib/source_annotation_extractor.rb +62 -0
- data/lib/tasks/annotations.rake +23 -0
- data/lib/tasks/databases.rake +328 -133
- data/lib/tasks/documentation.rake +72 -68
- data/lib/tasks/framework.rake +99 -58
- data/lib/tasks/log.rake +9 -0
- data/lib/tasks/misc.rake +2 -17
- data/lib/tasks/rails.rb +2 -2
- data/lib/tasks/routes.rake +17 -0
- data/lib/tasks/statistics.rake +10 -8
- data/lib/tasks/testing.rake +99 -31
- data/lib/tasks/tmp.rake +37 -0
- data/lib/test_help.rb +8 -5
- data/lib/webrick_server.rb +11 -16
- metadata +312 -272
- data/bin/breakpointer +0 -3
- data/builtin/controllers/rails_info_controller.rb +0 -11
- data/configs/database.yml +0 -85
- data/lib/binding_of_caller.rb +0 -85
- data/lib/breakpoint.rb +0 -523
- data/lib/breakpoint_client.rb +0 -196
- data/lib/commands/breakpointer.rb +0 -1
- data/lib/rails_generator/generators/components/scaffold/templates/form.rhtml +0 -3
- data/lib/rails_generator/generators/components/scaffold/templates/form_scaffolding.rhtml +0 -1
- data/lib/rails_generator/generators/components/scaffold/templates/layout.rhtml +0 -13
- data/lib/rails_generator/generators/components/scaffold/templates/view_edit.rhtml +0 -9
- data/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +0 -27
- data/lib/rails_generator/generators/components/scaffold/templates/view_new.rhtml +0 -8
- data/lib/rails_generator/generators/components/scaffold/templates/view_show.rhtml +0 -8
- data/lib/rails_generator/generators/components/web_service/USAGE +0 -28
- data/lib/rails_generator/generators/components/web_service/templates/api_definition.rb +0 -5
- data/lib/rails_generator/generators/components/web_service/templates/controller.rb +0 -8
- data/lib/rails_generator/generators/components/web_service/templates/functional_test.rb +0 -19
- data/lib/rails_generator/generators/components/web_service/web_service_generator.rb +0 -29
- data/lib/tasks/javascripts.rake +0 -6
data/lib/initializer.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require 'set'
|
3
|
-
require
|
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
|
+
|
4
11
|
|
5
12
|
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
|
6
13
|
|
@@ -16,7 +23,7 @@ module Rails
|
|
16
23
|
# through the block running:
|
17
24
|
#
|
18
25
|
# Rails::Initializer.run do |config|
|
19
|
-
# config.frameworks -= [ :
|
26
|
+
# config.frameworks -= [ :action_mailer ]
|
20
27
|
# end
|
21
28
|
#
|
22
29
|
# This will use the default configuration options from Rails::Configuration,
|
@@ -27,7 +34,7 @@ module Rails
|
|
27
34
|
|
28
35
|
# The set of loaded plugins.
|
29
36
|
attr_reader :loaded_plugins
|
30
|
-
|
37
|
+
|
31
38
|
# Runs the initializer. By default, this will invoke the #process method,
|
32
39
|
# which simply executes all of the initialization routines. Alternately,
|
33
40
|
# you can specify explicitly which initialization routine you want:
|
@@ -35,140 +42,199 @@ module Rails
|
|
35
42
|
# Rails::Initializer.run(:set_load_path)
|
36
43
|
#
|
37
44
|
# This is useful if you only want the load path initialized, without
|
38
|
-
# incuring the overhead of completely loading the entire environment.
|
45
|
+
# incuring the overhead of completely loading the entire environment.
|
39
46
|
def self.run(command = :process, configuration = Configuration.new)
|
40
47
|
yield configuration if block_given?
|
41
48
|
initializer = new configuration
|
42
49
|
initializer.send(command)
|
43
50
|
initializer
|
44
51
|
end
|
45
|
-
|
52
|
+
|
46
53
|
# Create a new Initializer instance that references the given Configuration
|
47
54
|
# instance.
|
48
55
|
def initialize(configuration)
|
49
56
|
@configuration = configuration
|
50
|
-
@loaded_plugins =
|
57
|
+
@loaded_plugins = []
|
51
58
|
end
|
52
59
|
|
53
60
|
# Sequentially step through all of the available initialization routines,
|
54
61
|
# in order:
|
55
62
|
#
|
63
|
+
# * #check_ruby_version
|
56
64
|
# * #set_load_path
|
57
|
-
# * #set_connection_adapters
|
58
65
|
# * #require_frameworks
|
66
|
+
# * #set_autoload_paths
|
67
|
+
# * add_plugin_load_paths
|
59
68
|
# * #load_environment
|
69
|
+
# * #initialize_encoding
|
60
70
|
# * #initialize_database
|
61
71
|
# * #initialize_logger
|
62
72
|
# * #initialize_framework_logging
|
63
73
|
# * #initialize_framework_views
|
64
|
-
# * #initialize_routing
|
65
74
|
# * #initialize_dependency_mechanism
|
66
|
-
# * #initialize_breakpoints
|
67
75
|
# * #initialize_whiny_nils
|
76
|
+
# * #initialize_temporary_directories
|
68
77
|
# * #initialize_framework_settings
|
69
|
-
# * #
|
78
|
+
# * #add_support_load_paths
|
70
79
|
# * #load_plugins
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
# Configuration instance.
|
80
|
+
# * #load_observers
|
81
|
+
# * #initialize_routing
|
82
|
+
# * #after_initialize
|
83
|
+
# * #load_application_initializers
|
76
84
|
def process
|
85
|
+
check_ruby_version
|
77
86
|
set_load_path
|
78
|
-
|
79
|
-
|
87
|
+
|
80
88
|
require_frameworks
|
89
|
+
set_autoload_paths
|
90
|
+
add_plugin_load_paths
|
81
91
|
load_environment
|
82
92
|
|
93
|
+
initialize_encoding
|
83
94
|
initialize_database
|
84
95
|
initialize_logger
|
85
96
|
initialize_framework_logging
|
86
97
|
initialize_framework_views
|
87
98
|
initialize_dependency_mechanism
|
88
|
-
initialize_breakpoints
|
89
99
|
initialize_whiny_nils
|
90
|
-
|
100
|
+
initialize_temporary_directories
|
91
101
|
initialize_framework_settings
|
92
|
-
|
93
|
-
|
94
|
-
# could overwrite anything set from the defaults/global through
|
95
|
-
# the individual base class configurations.
|
96
|
-
load_environment
|
97
|
-
|
98
|
-
load_framework_info
|
102
|
+
|
103
|
+
add_support_load_paths
|
99
104
|
|
100
105
|
load_plugins
|
101
106
|
|
107
|
+
# Observers are loaded after plugins in case Observers or observed models are modified by plugins.
|
108
|
+
load_observers
|
109
|
+
|
102
110
|
# Routing must be initialized after plugins to allow the former to extend the routes
|
103
111
|
initialize_routing
|
112
|
+
|
113
|
+
# the framework is now fully initialized
|
114
|
+
after_initialize
|
115
|
+
|
116
|
+
load_application_initializers
|
104
117
|
end
|
105
|
-
|
118
|
+
|
119
|
+
# Check for valid Ruby version
|
120
|
+
# This is done in an external file, so we can use it
|
121
|
+
# from the `rails` program as well without duplication.
|
122
|
+
def check_ruby_version
|
123
|
+
require 'ruby_version_check'
|
124
|
+
end
|
125
|
+
|
106
126
|
# Set the <tt>$LOAD_PATH</tt> based on the value of
|
107
127
|
# Configuration#load_paths. Duplicates are removed.
|
108
128
|
def set_load_path
|
109
|
-
|
129
|
+
load_paths = configuration.load_paths + configuration.framework_paths
|
130
|
+
load_paths.reverse_each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) }
|
110
131
|
$LOAD_PATH.uniq!
|
111
132
|
end
|
112
|
-
|
113
|
-
#
|
114
|
-
#
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
133
|
+
|
134
|
+
# Set the paths from which Rails will automatically load source files, and
|
135
|
+
# the load_once paths.
|
136
|
+
def set_autoload_paths
|
137
|
+
Dependencies.load_paths = configuration.load_paths.uniq
|
138
|
+
Dependencies.load_once_paths = configuration.load_once_paths.uniq
|
139
|
+
|
140
|
+
extra = Dependencies.load_once_paths - Dependencies.load_paths
|
141
|
+
unless extra.empty?
|
142
|
+
abort <<-end_error
|
143
|
+
load_once_paths must be a subset of the load_paths.
|
144
|
+
Extra items in load_once_paths: #{extra * ','}
|
145
|
+
end_error
|
146
|
+
end
|
147
|
+
|
148
|
+
# Freeze the arrays so future modifications will fail rather than do nothing mysteriously
|
149
|
+
configuration.load_once_paths.freeze
|
119
150
|
end
|
120
|
-
|
151
|
+
|
121
152
|
# Requires all frameworks specified by the Configuration#frameworks
|
122
153
|
# list. By default, all frameworks (ActiveRecord, ActiveSupport,
|
123
|
-
# ActionPack, ActionMailer, and
|
154
|
+
# ActionPack, ActionMailer, and ActiveResource) are loaded.
|
124
155
|
def require_frameworks
|
125
156
|
configuration.frameworks.each { |framework| require(framework.to_s) }
|
157
|
+
rescue LoadError => e
|
158
|
+
# re-raise because Mongrel would swallow it
|
159
|
+
raise e.to_s
|
126
160
|
end
|
127
|
-
|
128
|
-
#
|
129
|
-
|
130
|
-
|
131
|
-
|
161
|
+
|
162
|
+
# Add the load paths used by support functions such as the info controller
|
163
|
+
def add_support_load_paths
|
164
|
+
end
|
165
|
+
|
166
|
+
# Adds all load paths from plugins to the global set of load paths, so that
|
167
|
+
# code from plugins can be required (explicitly or automatically via Dependencies).
|
168
|
+
def add_plugin_load_paths
|
169
|
+
plugin_loader.add_plugin_load_paths
|
132
170
|
end
|
133
171
|
|
134
172
|
# Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
|
135
173
|
# defaults to <tt>vendor/plugins</tt> but may also be set to a list of
|
136
174
|
# paths, such as
|
137
|
-
# config.plugin_paths = [
|
175
|
+
# config.plugin_paths = ["#{RAILS_ROOT}/lib/plugins", "#{RAILS_ROOT}/vendor/plugins"]
|
138
176
|
#
|
139
|
-
#
|
140
|
-
# *
|
141
|
-
# *
|
177
|
+
# In the default implementation, as each plugin discovered in <tt>plugin_paths</tt> is initialized:
|
178
|
+
# * its +lib+ directory, if present, is added to the load path (immediately after the applications lib directory)
|
179
|
+
# * <tt>init.rb</tt> is evaluated, if present
|
142
180
|
#
|
143
181
|
# After all plugins are loaded, duplicates are removed from the load path.
|
182
|
+
# If an array of plugin names is specified in config.plugins, only those plugins will be loaded
|
183
|
+
# and they plugins will be loaded in that order. Otherwise, plugins are loaded in alphabetical
|
184
|
+
# order.
|
185
|
+
#
|
186
|
+
# if config.plugins ends contains :all then the named plugins will be loaded in the given order and all other
|
187
|
+
# plugins will be loaded in alphabetical order
|
144
188
|
def load_plugins
|
145
|
-
|
146
|
-
|
189
|
+
plugin_loader.load_plugins
|
190
|
+
end
|
191
|
+
|
192
|
+
def plugin_loader
|
193
|
+
@plugin_loader ||= configuration.plugin_loader.new(self)
|
147
194
|
end
|
148
195
|
|
149
196
|
# Loads the environment specified by Configuration#environment_path, which
|
150
|
-
# is typically one of development,
|
197
|
+
# is typically one of development, test, or production.
|
151
198
|
def load_environment
|
152
199
|
silence_warnings do
|
200
|
+
return if @environment_loaded
|
201
|
+
@environment_loaded = true
|
202
|
+
|
153
203
|
config = configuration
|
154
204
|
constants = self.class.constants
|
155
|
-
|
205
|
+
|
206
|
+
eval(IO.read(configuration.environment_path), binding, configuration.environment_path)
|
207
|
+
|
156
208
|
(self.class.constants - constants).each do |const|
|
157
209
|
Object.const_set(const, self.class.const_get(const))
|
158
210
|
end
|
159
211
|
end
|
160
212
|
end
|
161
|
-
|
213
|
+
|
214
|
+
def load_observers
|
215
|
+
if configuration.frameworks.include?(:active_record)
|
216
|
+
ActiveRecord::Base.instantiate_observers
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
# This initialization sets $KCODE to 'u' to enable the multibyte safe operations.
|
221
|
+
# Plugin authors supporting other encodings should override this behaviour and
|
222
|
+
# set the relevant +default_charset+ on ActionController::Base
|
223
|
+
def initialize_encoding
|
224
|
+
$KCODE='u'
|
225
|
+
end
|
226
|
+
|
162
227
|
# This initialization routine does nothing unless <tt>:active_record</tt>
|
163
228
|
# is one of the frameworks to load (Configuration#frameworks). If it is,
|
164
229
|
# this sets the database configuration from Configuration#database_configuration
|
165
230
|
# and then establishes the connection.
|
166
231
|
def initialize_database
|
167
|
-
|
168
|
-
|
169
|
-
|
232
|
+
if configuration.frameworks.include?(:active_record)
|
233
|
+
ActiveRecord::Base.configurations = configuration.database_configuration
|
234
|
+
ActiveRecord::Base.establish_connection
|
235
|
+
end
|
170
236
|
end
|
171
|
-
|
237
|
+
|
172
238
|
# If the +RAILS_DEFAULT_LOGGER+ constant is already set, this initialization
|
173
239
|
# routine does nothing. If the constant is not set, and Configuration#logger
|
174
240
|
# is not +nil+, this also does nothing. Otherwise, a new logger instance
|
@@ -183,21 +249,22 @@ module Rails
|
|
183
249
|
|
184
250
|
unless logger = configuration.logger
|
185
251
|
begin
|
186
|
-
logger =
|
187
|
-
logger.level =
|
188
|
-
|
189
|
-
|
190
|
-
logger
|
252
|
+
logger = ActiveSupport::BufferedLogger.new(configuration.log_path)
|
253
|
+
logger.level = ActiveSupport::BufferedLogger.const_get(configuration.log_level.to_s.upcase)
|
254
|
+
logger.auto_flushing = false if configuration.environment == "production"
|
255
|
+
rescue StandardError =>e
|
256
|
+
logger = ActiveSupport::BufferedLogger.new(STDERR)
|
257
|
+
logger.level = ActiveSupport::BufferedLogger::WARN
|
191
258
|
logger.warn(
|
192
259
|
"Rails Error: Unable to access log file. Please ensure that #{configuration.log_path} exists and is chmod 0666. " +
|
193
260
|
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
|
194
261
|
)
|
195
262
|
end
|
196
263
|
end
|
197
|
-
|
264
|
+
|
198
265
|
silence_warnings { Object.const_set "RAILS_DEFAULT_LOGGER", logger }
|
199
266
|
end
|
200
|
-
|
267
|
+
|
201
268
|
# Sets the logger for ActiveRecord, ActionController, and ActionMailer
|
202
269
|
# (but only for those frameworks that are to be loaded). If the framework's
|
203
270
|
# logger is already set, it is not changed, otherwise it is set to use
|
@@ -207,15 +274,14 @@ module Rails
|
|
207
274
|
framework.to_s.camelize.constantize.const_get("Base").logger ||= RAILS_DEFAULT_LOGGER
|
208
275
|
end
|
209
276
|
end
|
210
|
-
|
211
|
-
# Sets
|
277
|
+
|
278
|
+
# Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+
|
212
279
|
# (but only for those frameworks that are to be loaded). If the framework's
|
213
|
-
#
|
280
|
+
# paths have already been set, it is not changed, otherwise it is
|
214
281
|
# set to use Configuration#view_path.
|
215
282
|
def initialize_framework_views
|
216
|
-
|
217
|
-
|
218
|
-
end
|
283
|
+
ActionMailer::Base.template_root ||= configuration.view_path if configuration.frameworks.include?(:action_mailer)
|
284
|
+
ActionController::Base.view_paths = [configuration.view_path] if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty?
|
219
285
|
end
|
220
286
|
|
221
287
|
# If ActionController is not one of the loaded frameworks (Configuration#frameworks)
|
@@ -223,21 +289,15 @@ module Rails
|
|
223
289
|
# loading module used to lazily load controllers (Configuration#controller_paths).
|
224
290
|
def initialize_routing
|
225
291
|
return unless configuration.frameworks.include?(:action_controller)
|
292
|
+
ActionController::Routing.controller_paths = configuration.controller_paths
|
226
293
|
ActionController::Routing::Routes.reload
|
227
|
-
Object.const_set "Controllers", Dependencies::LoadingModule.root(*configuration.controller_paths)
|
228
294
|
end
|
229
|
-
|
295
|
+
|
230
296
|
# Sets the dependency loading mechanism based on the value of
|
231
297
|
# Configuration#cache_classes.
|
232
298
|
def initialize_dependency_mechanism
|
233
299
|
Dependencies.mechanism = configuration.cache_classes ? :require : :load
|
234
300
|
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
301
|
|
242
302
|
# Loads support for "whiny nil" (noisy warnings when methods are invoked
|
243
303
|
# on +nil+ values) if Configuration#whiny_nils is true.
|
@@ -245,7 +305,19 @@ module Rails
|
|
245
305
|
require('active_support/whiny_nil') if configuration.whiny_nils
|
246
306
|
end
|
247
307
|
|
248
|
-
|
308
|
+
def initialize_temporary_directories
|
309
|
+
if configuration.frameworks.include?(:action_controller)
|
310
|
+
session_path = "#{configuration.root_path}/tmp/sessions/"
|
311
|
+
ActionController::Base.session_options[:tmpdir] = File.exist?(session_path) ? session_path : Dir::tmpdir
|
312
|
+
|
313
|
+
cache_path = "#{configuration.root_path}/tmp/cache/"
|
314
|
+
if File.exist?(cache_path)
|
315
|
+
ActionController::Base.fragment_cache_store = :file_store, cache_path
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
# Initializes framework-specific settings for each of the loaded frameworks
|
249
321
|
# (Configuration#frameworks). The available settings map to the accessors
|
250
322
|
# on each of the corresponding Base classes.
|
251
323
|
def initialize_framework_settings
|
@@ -258,62 +330,19 @@ module Rails
|
|
258
330
|
end
|
259
331
|
end
|
260
332
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
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
|
333
|
+
# Fires the user-supplied after_initialize block (Configuration#after_initialize)
|
334
|
+
def after_initialize
|
335
|
+
configuration.after_initialize_blocks.each do |block|
|
336
|
+
block.call
|
277
337
|
end
|
338
|
+
end
|
278
339
|
|
279
|
-
|
280
|
-
|
340
|
+
def load_application_initializers
|
341
|
+
Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
|
342
|
+
load(initializer)
|
281
343
|
end
|
344
|
+
end
|
282
345
|
|
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
346
|
end
|
318
347
|
|
319
348
|
# The Configuration class holds all the parameters for the Initializer and
|
@@ -326,33 +355,28 @@ module Rails
|
|
326
355
|
# config = Rails::Configuration.new
|
327
356
|
# Rails::Initializer.run(:process, config)
|
328
357
|
class Configuration
|
358
|
+
# The application's base directory.
|
359
|
+
attr_reader :root_path
|
360
|
+
|
329
361
|
# A stub for setting options on ActionController::Base
|
330
362
|
attr_accessor :action_controller
|
331
|
-
|
363
|
+
|
332
364
|
# A stub for setting options on ActionMailer::Base
|
333
365
|
attr_accessor :action_mailer
|
334
|
-
|
366
|
+
|
335
367
|
# A stub for setting options on ActionView::Base
|
336
368
|
attr_accessor :action_view
|
337
|
-
|
338
|
-
# A stub for setting options on ActionWebService::Base
|
339
|
-
attr_accessor :action_web_service
|
340
|
-
|
369
|
+
|
341
370
|
# A stub for setting options on ActiveRecord::Base
|
342
371
|
attr_accessor :active_record
|
343
|
-
|
344
|
-
#
|
345
|
-
attr_accessor :
|
346
|
-
|
372
|
+
|
373
|
+
# A stub for setting options on ActiveRecord::Base
|
374
|
+
attr_accessor :active_resource
|
375
|
+
|
347
376
|
# Whether or not classes should be cached (set to false if you want
|
348
377
|
# application classes to be reloaded on each request)
|
349
378
|
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
|
-
|
379
|
+
|
356
380
|
# The list of paths that should be searched for controllers. (Defaults
|
357
381
|
# to <tt>app/controllers</tt> and <tt>components</tt>.)
|
358
382
|
attr_accessor :controller_paths
|
@@ -360,70 +384,128 @@ module Rails
|
|
360
384
|
# The path to the database configuration file to use. (Defaults to
|
361
385
|
# <tt>config/database.yml</tt>.)
|
362
386
|
attr_accessor :database_configuration_file
|
363
|
-
|
387
|
+
|
364
388
|
# The list of rails framework components that should be loaded. (Defaults
|
365
389
|
# to <tt>:active_record</tt>, <tt>:action_controller</tt>,
|
366
390
|
# <tt>:action_view</tt>, <tt>:action_mailer</tt>, and
|
367
|
-
# <tt>:
|
391
|
+
# <tt>:active_resource</tt>).
|
368
392
|
attr_accessor :frameworks
|
369
|
-
|
393
|
+
|
370
394
|
# An array of additional paths to prepend to the load path. By default,
|
371
395
|
# all +app+, +lib+, +vendor+ and mock paths are included in this list.
|
372
396
|
attr_accessor :load_paths
|
373
|
-
|
397
|
+
|
398
|
+
# An array of paths from which Rails will automatically load from only once.
|
399
|
+
# All elements of this array must also be in +load_paths+.
|
400
|
+
attr_accessor :load_once_paths
|
401
|
+
|
374
402
|
# The log level to use for the default Rails logger. In production mode,
|
375
403
|
# this defaults to <tt>:info</tt>. In development mode, it defaults to
|
376
404
|
# <tt>:debug</tt>.
|
377
405
|
attr_accessor :log_level
|
378
|
-
|
406
|
+
|
379
407
|
# The path to the log file to use. Defaults to log/#{environment}.log
|
380
408
|
# (e.g. log/development.log or log/production.log).
|
381
409
|
attr_accessor :log_path
|
382
|
-
|
410
|
+
|
383
411
|
# The specific logger to use. By default, a logger will be created and
|
384
412
|
# initialized using #log_path and #log_level, but a programmer may
|
385
413
|
# specifically set the logger to use via this accessor and it will be
|
386
414
|
# used directly.
|
387
415
|
attr_accessor :logger
|
388
|
-
|
416
|
+
|
389
417
|
# The root of the application's views. (Defaults to <tt>app/views</tt>.)
|
390
418
|
attr_accessor :view_path
|
391
|
-
|
419
|
+
|
392
420
|
# Set to +true+ if you want to be warned (noisily) when you try to invoke
|
393
421
|
# any method of +nil+. Set to +false+ for the standard Ruby behavior.
|
394
422
|
attr_accessor :whiny_nils
|
395
|
-
|
423
|
+
|
424
|
+
# The list of plugins to load. If this is set to <tt>nil</tt>, all plugins will
|
425
|
+
# be loaded. If this is set to <tt>[]</tt>, no plugins will be loaded. Otherwise,
|
426
|
+
# plugins will be loaded in the order specified.
|
427
|
+
attr_reader :plugins
|
428
|
+
def plugins=(plugins)
|
429
|
+
@plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym }
|
430
|
+
end
|
431
|
+
|
396
432
|
# The path to the root of the plugins directory. By default, it is in
|
397
433
|
# <tt>vendor/plugins</tt>.
|
398
434
|
attr_accessor :plugin_paths
|
399
435
|
|
436
|
+
# The classes that handle finding the desired plugins that you'd like to load for
|
437
|
+
# your application. By default it is the Rails::Plugin::FileSystemLocator which finds
|
438
|
+
# plugins to load in <tt>vendor/plugins</tt>. You can hook into gem location by subclassing
|
439
|
+
# Rails::Plugin::Locator and adding it onto the list of <tt>plugin_locators</tt>.
|
440
|
+
attr_accessor :plugin_locators
|
441
|
+
|
442
|
+
# The class that handles loading each plugin. Defaults to Rails::Plugin::Loader, but
|
443
|
+
# a sub class would have access to fine grained modification of the loading behavior. See
|
444
|
+
# the implementation of Rails::Plugin::Loader for more details.
|
445
|
+
attr_accessor :plugin_loader
|
446
|
+
|
447
|
+
# Deprecated options:
|
448
|
+
def breakpoint_server(_ = nil)
|
449
|
+
$stderr.puts %(
|
450
|
+
*******************************************************************
|
451
|
+
* config.breakpoint_server has been deprecated and has no effect. *
|
452
|
+
*******************************************************************
|
453
|
+
)
|
454
|
+
end
|
455
|
+
alias_method :breakpoint_server=, :breakpoint_server
|
456
|
+
|
400
457
|
# Create a new Configuration instance, initialized with the default
|
401
458
|
# values.
|
402
459
|
def initialize
|
460
|
+
set_root_path!
|
461
|
+
|
403
462
|
self.frameworks = default_frameworks
|
404
463
|
self.load_paths = default_load_paths
|
464
|
+
self.load_once_paths = default_load_once_paths
|
405
465
|
self.log_path = default_log_path
|
406
466
|
self.log_level = default_log_level
|
407
467
|
self.view_path = default_view_path
|
408
468
|
self.controller_paths = default_controller_paths
|
409
469
|
self.cache_classes = default_cache_classes
|
410
|
-
self.breakpoint_server = default_breakpoint_server
|
411
470
|
self.whiny_nils = default_whiny_nils
|
471
|
+
self.plugins = default_plugins
|
412
472
|
self.plugin_paths = default_plugin_paths
|
473
|
+
self.plugin_locators = default_plugin_locators
|
474
|
+
self.plugin_loader = default_plugin_loader
|
413
475
|
self.database_configuration_file = default_database_configuration_file
|
414
476
|
|
415
477
|
for framework in default_frameworks
|
416
|
-
self.send("#{framework}=", OrderedOptions.new)
|
478
|
+
self.send("#{framework}=", Rails::OrderedOptions.new)
|
417
479
|
end
|
418
480
|
end
|
419
|
-
|
481
|
+
|
482
|
+
# Set the root_path to RAILS_ROOT and canonicalize it.
|
483
|
+
def set_root_path!
|
484
|
+
raise 'RAILS_ROOT is not set' unless defined?(::RAILS_ROOT)
|
485
|
+
raise 'RAILS_ROOT is not a directory' unless File.directory?(::RAILS_ROOT)
|
486
|
+
|
487
|
+
@root_path =
|
488
|
+
# Pathname is incompatible with Windows, but Windows doesn't have
|
489
|
+
# real symlinks so File.expand_path is safe.
|
490
|
+
if RUBY_PLATFORM =~ /(:?mswin|mingw)/
|
491
|
+
File.expand_path(::RAILS_ROOT)
|
492
|
+
|
493
|
+
# Otherwise use Pathname#realpath which respects symlinks.
|
494
|
+
else
|
495
|
+
Pathname.new(::RAILS_ROOT).realpath.to_s
|
496
|
+
end
|
497
|
+
|
498
|
+
Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT)
|
499
|
+
::RAILS_ROOT.replace @root_path
|
500
|
+
end
|
501
|
+
|
420
502
|
# Loads and returns the contents of the #database_configuration_file. The
|
421
503
|
# contents of the file are processed via ERB before being sent through
|
422
504
|
# YAML::load.
|
423
505
|
def database_configuration
|
424
506
|
YAML::load(ERB.new(IO.read(database_configuration_file)).result)
|
425
507
|
end
|
426
|
-
|
508
|
+
|
427
509
|
# The path to the current environment's file (development.rb, etc.). By
|
428
510
|
# default the file is at <tt>config/environments/#{environment}.rb</tt>.
|
429
511
|
def environment_path
|
@@ -436,91 +518,138 @@ module Rails
|
|
436
518
|
::RAILS_ENV
|
437
519
|
end
|
438
520
|
|
521
|
+
# Adds a block which will be executed after rails has been fully initialized.
|
522
|
+
# Useful for per-environment configuration which depends on the framework being
|
523
|
+
# fully initialized.
|
524
|
+
def after_initialize(&after_initialize_block)
|
525
|
+
after_initialize_blocks << after_initialize_block if after_initialize_block
|
526
|
+
end
|
527
|
+
|
528
|
+
# Returns the blocks added with Configuration#after_initialize
|
529
|
+
def after_initialize_blocks
|
530
|
+
@after_initialize_blocks ||= []
|
531
|
+
end
|
532
|
+
|
533
|
+
# Add a preparation callback that will run before every request in development
|
534
|
+
# mode, or before the first request in production.
|
535
|
+
#
|
536
|
+
# See Dispatcher#to_prepare.
|
537
|
+
def to_prepare(&callback)
|
538
|
+
require 'dispatcher' unless defined?(::Dispatcher)
|
539
|
+
Dispatcher.to_prepare(&callback)
|
540
|
+
end
|
541
|
+
|
542
|
+
def builtin_directories
|
543
|
+
# Include builtins only in the development environment.
|
544
|
+
(environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
|
545
|
+
end
|
546
|
+
|
547
|
+
def framework_paths
|
548
|
+
paths = %w(railties railties/lib activesupport/lib)
|
549
|
+
paths << 'actionpack/lib' if frameworks.include? :action_controller or frameworks.include? :action_view
|
550
|
+
|
551
|
+
[:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
|
552
|
+
paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include? framework
|
553
|
+
end
|
554
|
+
|
555
|
+
paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
|
556
|
+
end
|
557
|
+
|
439
558
|
private
|
440
|
-
def
|
441
|
-
::
|
559
|
+
def framework_root_path
|
560
|
+
defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails"
|
442
561
|
end
|
443
562
|
|
444
563
|
def default_frameworks
|
445
|
-
[ :active_record, :action_controller, :action_view, :action_mailer, :
|
564
|
+
[ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
|
446
565
|
end
|
447
|
-
|
566
|
+
|
448
567
|
def default_load_paths
|
449
568
|
paths = ["#{root_path}/test/mocks/#{environment}"]
|
450
569
|
|
451
|
-
#
|
452
|
-
#
|
453
|
-
|
570
|
+
# Add the app's controller directory
|
571
|
+
paths.concat(Dir["#{root_path}/app/controllers/"])
|
572
|
+
|
573
|
+
# Then components subdirectories.
|
454
574
|
paths.concat(Dir["#{root_path}/components/[_a-z]*"])
|
455
575
|
|
456
576
|
# Followed by the standard includes.
|
457
|
-
# TODO: Don't include dirs for frameworks that are not used
|
458
577
|
paths.concat %w(
|
459
|
-
app
|
460
|
-
app/models
|
578
|
+
app
|
579
|
+
app/models
|
461
580
|
app/controllers
|
462
581
|
app/helpers
|
463
582
|
app/services
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
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
|
583
|
+
components
|
584
|
+
config
|
585
|
+
lib
|
586
|
+
vendor
|
476
587
|
).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
|
588
|
+
|
589
|
+
paths.concat builtin_directories
|
590
|
+
end
|
591
|
+
|
592
|
+
# Doesn't matter since plugins aren't in load_paths yet.
|
593
|
+
def default_load_once_paths
|
594
|
+
[]
|
477
595
|
end
|
478
596
|
|
479
597
|
def default_log_path
|
480
598
|
File.join(root_path, 'log', "#{environment}.log")
|
481
599
|
end
|
482
|
-
|
600
|
+
|
483
601
|
def default_log_level
|
484
602
|
environment == 'production' ? :info : :debug
|
485
603
|
end
|
486
|
-
|
604
|
+
|
487
605
|
def default_database_configuration_file
|
488
606
|
File.join(root_path, 'config', 'database.yml')
|
489
607
|
end
|
490
|
-
|
608
|
+
|
491
609
|
def default_view_path
|
492
610
|
File.join(root_path, 'app', 'views')
|
493
611
|
end
|
494
|
-
|
612
|
+
|
495
613
|
def default_controller_paths
|
496
|
-
[
|
614
|
+
paths = [File.join(root_path, 'app', 'controllers')]
|
615
|
+
paths.concat builtin_directories
|
616
|
+
paths
|
497
617
|
end
|
498
|
-
|
618
|
+
|
499
619
|
def default_dependency_mechanism
|
500
620
|
:load
|
501
621
|
end
|
502
|
-
|
622
|
+
|
503
623
|
def default_cache_classes
|
504
624
|
false
|
505
625
|
end
|
506
|
-
|
507
|
-
def default_breakpoint_server
|
508
|
-
false
|
509
|
-
end
|
510
|
-
|
626
|
+
|
511
627
|
def default_whiny_nils
|
512
628
|
false
|
513
629
|
end
|
514
630
|
|
631
|
+
def default_plugins
|
632
|
+
nil
|
633
|
+
end
|
634
|
+
|
515
635
|
def default_plugin_paths
|
516
636
|
["#{root_path}/vendor/plugins"]
|
517
637
|
end
|
638
|
+
|
639
|
+
def default_plugin_locators
|
640
|
+
[Plugin::FileSystemLocator]
|
641
|
+
end
|
642
|
+
|
643
|
+
def default_plugin_loader
|
644
|
+
Plugin::Loader
|
645
|
+
end
|
518
646
|
end
|
519
647
|
end
|
520
648
|
|
521
649
|
# Needs to be duplicated from Active Support since its needed before Active
|
522
|
-
# Support is available.
|
523
|
-
|
650
|
+
# Support is available. Here both Options and Hash are namespaced to prevent
|
651
|
+
# conflicts with other implementations AND with the classes residing in ActiveSupport.
|
652
|
+
class Rails::OrderedOptions < Array #:nodoc:
|
524
653
|
def []=(key, value)
|
525
654
|
key = key.to_sym
|
526
655
|
|