rails 0.14.2 → 0.14.3
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 +83 -0
- data/README +16 -53
- data/Rakefile +10 -11
- data/bin/about +3 -0
- data/bin/plugin +3 -0
- data/configs/database.yml +65 -3
- data/configs/lighttpd.conf +40 -0
- data/environments/boot.rb +2 -2
- data/environments/environment.rb +3 -3
- data/environments/test.rb +1 -7
- data/helpers/test_helper.rb +19 -4
- data/html/javascripts/controls.js +18 -5
- data/html/javascripts/dragdrop.js +6 -3
- data/html/javascripts/effects.js +181 -290
- data/html/javascripts/prototype.js +13 -11
- data/lib/commands/about.rb +2 -0
- data/lib/commands/plugin.rb +823 -0
- data/lib/commands/process/reaper.rb +3 -3
- data/lib/commands/server.rb +23 -54
- data/lib/commands/servers/lighttpd.rb +56 -0
- data/lib/commands/servers/webrick.rb +59 -0
- data/lib/dispatcher.rb +30 -8
- data/lib/fcgi_handler.rb +6 -1
- data/lib/initializer.rb +107 -42
- data/lib/rails_generator/generators/applications/app/app_generator.rb +14 -12
- data/lib/rails_generator/generators/components/migration/migration_generator.rb +52 -5
- data/lib/rails_generator/generators/components/model/templates/fixtures.yml +2 -2
- data/lib/rails_generator/generators/components/model/templates/unit_test.rb +1 -5
- data/lib/rails_generator/generators/components/plugin/USAGE +33 -0
- data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +33 -0
- data/lib/rails_generator/generators/components/plugin/templates/README +4 -0
- data/lib/rails_generator/generators/components/plugin/templates/Rakefile +22 -0
- data/lib/rails_generator/generators/components/plugin/templates/USAGE +8 -0
- data/lib/rails_generator/generators/components/plugin/templates/generator.rb +8 -0
- data/lib/rails_generator/generators/components/plugin/templates/init.rb +1 -0
- data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +1 -0
- data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +4 -0
- data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +8 -0
- data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +6 -1
- data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +1 -1
- data/lib/rails_generator/generators/components/scaffold/templates/style.css +1 -1
- data/lib/rails_generator/lookup.rb +1 -0
- data/lib/rails_info.rb +94 -0
- data/lib/rails_version.rb +1 -1
- data/lib/tasks/databases.rake +8 -5
- data/lib/tasks/documentation.rake +34 -1
- data/lib/tasks/framework.rake +50 -12
- data/lib/tasks/misc.rake +5 -1
- data/lib/tasks/rails.rb +2 -2
- data/lib/tasks/testing.rake +14 -1
- metadata +28 -9
- data/html/javascripts/scriptaculous.js +0 -47
- data/html/javascripts/slider.js +0 -258
@@ -32,7 +32,7 @@ class ProgramProcess
|
|
32
32
|
# ProgramProcess.find_by_keyword("basecamp")
|
33
33
|
def find_by_keyword(keyword)
|
34
34
|
process_lines_with_keyword(keyword).split("\n").collect { |line|
|
35
|
-
next if line
|
35
|
+
next if line =~ /inq|ps axww|grep|spawn-fcgi|spawner|reaper/
|
36
36
|
pid, *command = line.split
|
37
37
|
new(pid, command.join(" "))
|
38
38
|
}.compact
|
@@ -40,7 +40,7 @@ class ProgramProcess
|
|
40
40
|
|
41
41
|
private
|
42
42
|
def process_lines_with_keyword(keyword)
|
43
|
-
`ps
|
43
|
+
`ps axww -o 'pid command' | grep #{keyword}`
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -127,4 +127,4 @@ ARGV.options do |opts|
|
|
127
127
|
opts.parse!
|
128
128
|
end
|
129
129
|
|
130
|
-
ProgramProcess.process_keywords(OPTIONS[:action], OPTIONS[:dispatcher])
|
130
|
+
ProgramProcess.process_keywords(OPTIONS[:action], OPTIONS[:dispatcher])
|
data/lib/commands/server.rb
CHANGED
@@ -1,59 +1,28 @@
|
|
1
|
-
require '
|
2
|
-
require 'optparse'
|
1
|
+
require 'active_support'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
:server_root => File.expand_path(RAILS_ROOT + "/public/"),
|
9
|
-
:server_type => WEBrick::SimpleServer,
|
10
|
-
:charset => "UTF-8",
|
11
|
-
:mime_types => WEBrick::HTTPUtils::DefaultMimeTypes
|
12
|
-
}
|
13
|
-
|
14
|
-
ARGV.options do |opts|
|
15
|
-
script_name = File.basename($0)
|
16
|
-
opts.banner = "Usage: ruby #{script_name} [options]"
|
17
|
-
|
18
|
-
opts.separator ""
|
19
|
-
|
20
|
-
opts.on("-p", "--port=port", Integer,
|
21
|
-
"Runs Rails on the specified port.",
|
22
|
-
"Default: 3000") { |OPTIONS[:port]| }
|
23
|
-
opts.on("-b", "--binding=ip", String,
|
24
|
-
"Binds Rails to the specified ip.",
|
25
|
-
"Default: 0.0.0.0") { |OPTIONS[:ip]| }
|
26
|
-
opts.on("-e", "--environment=name", String,
|
27
|
-
"Specifies the environment to run this server under (test/development/production).",
|
28
|
-
"Default: development") { |OPTIONS[:environment]| }
|
29
|
-
opts.on("-m", "--mime-types=filename", String,
|
30
|
-
"Specifies an Apache style mime.types configuration file to be used for mime types",
|
31
|
-
"Default: none") { |mime_types_file| OPTIONS[:mime_types] = WEBrick::HTTPUtils::load_mime_types(mime_types_file) }
|
32
|
-
|
33
|
-
opts.on("-d", "--daemon",
|
34
|
-
"Make Rails run as a Daemon (only works if fork is available -- meaning on *nix)."
|
35
|
-
) { OPTIONS[:server_type] = WEBrick::Daemon }
|
36
|
-
|
37
|
-
opts.on("-c", "--charset=charset", String,
|
38
|
-
"Set default charset for output.",
|
39
|
-
"Default: UTF-8") { |OPTIONS[:charset]| }
|
40
|
-
|
41
|
-
opts.separator ""
|
42
|
-
|
43
|
-
opts.on("-h", "--help",
|
44
|
-
"Show this help message.") { puts opts; exit }
|
45
|
-
|
46
|
-
opts.parse!
|
3
|
+
begin
|
4
|
+
require_library_or_gem 'fcgi'
|
5
|
+
rescue Exception
|
6
|
+
# FCGI not available
|
47
7
|
end
|
48
8
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
9
|
+
server = case ARGV.first
|
10
|
+
when "lighttpd"
|
11
|
+
ARGV.shift
|
12
|
+
when "webrick"
|
13
|
+
ARGV.shift
|
14
|
+
else
|
15
|
+
if RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `lighttpd -version` }.blank? && defined?(FCGI)
|
16
|
+
"lighttpd"
|
17
|
+
else
|
18
|
+
"webrick"
|
19
|
+
end
|
20
|
+
end
|
54
21
|
|
55
|
-
|
22
|
+
if server == "webrick"
|
23
|
+
puts "=> Booting WEBrick..."
|
24
|
+
else
|
25
|
+
puts "=> Booting lighttpd (use 'script/server webrick' to force WEBrick)"
|
26
|
+
end
|
56
27
|
|
57
|
-
|
58
|
-
puts "=> Ctrl-C to shutdown server; call with --help for options" if OPTIONS[:server_type] == WEBrick::SimpleServer
|
59
|
-
DispatchServlet.dispatch(OPTIONS)
|
28
|
+
require "commands/servers/#{server}"
|
@@ -0,0 +1,56 @@
|
|
1
|
+
unless RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `lighttpd -version` }.blank?
|
2
|
+
puts "PROBLEM: Lighttpd is not available on your system (or not in your path)"
|
3
|
+
exit 1
|
4
|
+
end
|
5
|
+
|
6
|
+
unless defined?(FCGI)
|
7
|
+
puts "PROBLEM: Lighttpd requires that the FCGI Ruby bindings are installed on the system"
|
8
|
+
exit 1
|
9
|
+
end
|
10
|
+
|
11
|
+
def tail_f(input)
|
12
|
+
loop do
|
13
|
+
line = input.gets
|
14
|
+
yield line if line
|
15
|
+
if input.eof?
|
16
|
+
sleep 1
|
17
|
+
input.seek(input.tell)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
config_file = "#{RAILS_ROOT}/config/lighttpd.conf"
|
23
|
+
|
24
|
+
unless File.exist?(config_file)
|
25
|
+
require 'fileutils'
|
26
|
+
source = File.expand_path(File.join(File.dirname(__FILE__),
|
27
|
+
"..", "..", "..", "configs", "lighttpd.conf"))
|
28
|
+
puts "=> #{config_file} not found, copying from #{source}"
|
29
|
+
FileUtils.cp source, config_file
|
30
|
+
end
|
31
|
+
|
32
|
+
port = IO.read(config_file).scan(/^server.port\s*=\s*(\d+)/).first rescue 3000
|
33
|
+
puts "=> Rails application started on http://0.0.0.0:#{port}"
|
34
|
+
|
35
|
+
if ARGV.first == "-d"
|
36
|
+
puts "=> Configure in config/lighttpd.conf"
|
37
|
+
detach = true
|
38
|
+
else
|
39
|
+
puts "=> Call with -d to detach (requires absolute paths in config/lighttpd.conf)"
|
40
|
+
puts "=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)"
|
41
|
+
detach = false
|
42
|
+
|
43
|
+
Process.detach(fork do
|
44
|
+
begin
|
45
|
+
File.open("#{RAILS_ROOT}/log/#{RAILS_ENV}.log", 'r') do |log|
|
46
|
+
log.seek(0, IO::SEEK_END)
|
47
|
+
tail_f(log) {|line| puts line}
|
48
|
+
end
|
49
|
+
rescue Exception
|
50
|
+
end
|
51
|
+
exit
|
52
|
+
end)
|
53
|
+
end
|
54
|
+
|
55
|
+
trap(:INT) {exit}
|
56
|
+
`lighttpd #{!detach ? "-D " : ""}-f #{config_file}`
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
OPTIONS = {
|
5
|
+
:port => 3000,
|
6
|
+
:ip => "0.0.0.0",
|
7
|
+
:environment => (ENV['RAILS_ENV'] || "development").dup,
|
8
|
+
:server_root => File.expand_path(RAILS_ROOT + "/public/"),
|
9
|
+
:server_type => WEBrick::SimpleServer,
|
10
|
+
:charset => "UTF-8",
|
11
|
+
:mime_types => WEBrick::HTTPUtils::DefaultMimeTypes
|
12
|
+
}
|
13
|
+
|
14
|
+
ARGV.options do |opts|
|
15
|
+
script_name = File.basename($0)
|
16
|
+
opts.banner = "Usage: ruby #{script_name} [options]"
|
17
|
+
|
18
|
+
opts.separator ""
|
19
|
+
|
20
|
+
opts.on("-p", "--port=port", Integer,
|
21
|
+
"Runs Rails on the specified port.",
|
22
|
+
"Default: 3000") { |OPTIONS[:port]| }
|
23
|
+
opts.on("-b", "--binding=ip", String,
|
24
|
+
"Binds Rails to the specified ip.",
|
25
|
+
"Default: 0.0.0.0") { |OPTIONS[:ip]| }
|
26
|
+
opts.on("-e", "--environment=name", String,
|
27
|
+
"Specifies the environment to run this server under (test/development/production).",
|
28
|
+
"Default: development") { |OPTIONS[:environment]| }
|
29
|
+
opts.on("-m", "--mime-types=filename", String,
|
30
|
+
"Specifies an Apache style mime.types configuration file to be used for mime types",
|
31
|
+
"Default: none") { |mime_types_file| OPTIONS[:mime_types] = WEBrick::HTTPUtils::load_mime_types(mime_types_file) }
|
32
|
+
|
33
|
+
opts.on("-d", "--daemon",
|
34
|
+
"Make Rails run as a Daemon (only works if fork is available -- meaning on *nix)."
|
35
|
+
) { OPTIONS[:server_type] = WEBrick::Daemon }
|
36
|
+
|
37
|
+
opts.on("-c", "--charset=charset", String,
|
38
|
+
"Set default charset for output.",
|
39
|
+
"Default: UTF-8") { |OPTIONS[:charset]| }
|
40
|
+
|
41
|
+
opts.separator ""
|
42
|
+
|
43
|
+
opts.on("-h", "--help",
|
44
|
+
"Show this help message.") { puts opts; exit }
|
45
|
+
|
46
|
+
opts.parse!
|
47
|
+
end
|
48
|
+
|
49
|
+
ENV["RAILS_ENV"] = OPTIONS[:environment]
|
50
|
+
RAILS_ENV.replace(OPTIONS[:environment]) if defined?(RAILS_ENV)
|
51
|
+
|
52
|
+
require RAILS_ROOT + "/config/environment"
|
53
|
+
require 'webrick_server'
|
54
|
+
|
55
|
+
OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT)
|
56
|
+
|
57
|
+
puts "=> Rails application started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
|
58
|
+
puts "=> Ctrl-C to shutdown server; call with --help for options" if OPTIONS[:server_type] == WEBrick::SimpleServer
|
59
|
+
DispatchServlet.dispatch(OPTIONS)
|
data/lib/dispatcher.rb
CHANGED
@@ -26,19 +26,24 @@
|
|
26
26
|
# the environment (when Dependencies.load? is true) after each request.
|
27
27
|
class Dispatcher
|
28
28
|
class << self
|
29
|
-
|
29
|
+
|
30
30
|
# Dispatch the given CGI request, using the given session options, and
|
31
|
-
# emitting the output via the given output.
|
32
|
-
|
33
|
-
|
31
|
+
# emitting the output via the given output. If you dispatch with your
|
32
|
+
# own CGI object be sure to handle the exceptions it raises on multipart
|
33
|
+
# requests (EOFError and ArgumentError).
|
34
|
+
def dispatch(cgi = nil, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, output = $stdout)
|
35
|
+
if cgi ||= new_cgi(output)
|
34
36
|
request, response = ActionController::CgiRequest.new(cgi, session_options), ActionController::CgiResponse.new(cgi)
|
35
37
|
prepare_application
|
36
38
|
ActionController::Routing::Routes.recognize!(request).process(request, response).out(output)
|
37
|
-
|
39
|
+
end
|
40
|
+
rescue Object => exception
|
41
|
+
failsafe_response(output, '500 Internal Server Error') do
|
38
42
|
ActionController::Base.process_with_exception(request, response, exception).out(output)
|
39
|
-
ensure
|
40
|
-
reset_after_dispatch
|
41
43
|
end
|
44
|
+
ensure
|
45
|
+
# Do not give a failsafe response here.
|
46
|
+
reset_after_dispatch
|
42
47
|
end
|
43
48
|
|
44
49
|
# Reset the application by clearing out loaded controllers, views, actions,
|
@@ -51,8 +56,15 @@ class Dispatcher
|
|
51
56
|
Dependencies.remove_subclasses_for(ActiveRecord::Base, ActiveRecord::Observer, ActionController::Base)
|
52
57
|
Dependencies.remove_subclasses_for(ActionMailer::Base) if defined?(ActionMailer::Base)
|
53
58
|
end
|
54
|
-
|
59
|
+
|
55
60
|
private
|
61
|
+
# CGI.new plus exception handling. CGI#read_multipart raises EOFError
|
62
|
+
# if body.empty? or body.size != Content-Length and raises ArgumentError
|
63
|
+
# if Content-Length is non-integer.
|
64
|
+
def new_cgi(output)
|
65
|
+
failsafe_response(output, '400 Bad Request') { CGI.new }
|
66
|
+
end
|
67
|
+
|
56
68
|
def prepare_application
|
57
69
|
ActionController::Routing::Routes.reload if Dependencies.load?
|
58
70
|
prepare_breakpoint
|
@@ -72,5 +84,15 @@ class Dispatcher
|
|
72
84
|
rescue
|
73
85
|
nil
|
74
86
|
end
|
87
|
+
|
88
|
+
# If the block raises, send status code as a last-ditch response.
|
89
|
+
def failsafe_response(output, status)
|
90
|
+
yield
|
91
|
+
rescue Object
|
92
|
+
begin
|
93
|
+
output.write "Status: #{status}\r\n"
|
94
|
+
rescue Object
|
95
|
+
end
|
96
|
+
end
|
75
97
|
end
|
76
98
|
end
|
data/lib/fcgi_handler.rb
CHANGED
@@ -6,7 +6,7 @@ require 'rbconfig'
|
|
6
6
|
class RailsFCGIHandler
|
7
7
|
SIGNALS = {
|
8
8
|
'HUP' => :reload,
|
9
|
-
'TERM' => :
|
9
|
+
'TERM' => :exit_now,
|
10
10
|
'USR1' => :exit,
|
11
11
|
'USR2' => :restart
|
12
12
|
}
|
@@ -117,6 +117,11 @@ class RailsFCGIHandler
|
|
117
117
|
dispatcher_log :warn, "Ignoring unsupported signal #{signal}."
|
118
118
|
end
|
119
119
|
|
120
|
+
def exit_now_handler(signal)
|
121
|
+
dispatcher_log :info, "asked to terminate immediately"
|
122
|
+
exit
|
123
|
+
end
|
124
|
+
|
120
125
|
def exit_handler(signal)
|
121
126
|
dispatcher_log :info, "asked to terminate ASAP"
|
122
127
|
@when_ready = :exit
|
data/lib/initializer.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'logger'
|
2
|
+
require 'set'
|
2
3
|
|
3
4
|
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
|
4
5
|
|
@@ -22,7 +23,10 @@ module Rails
|
|
22
23
|
class Initializer
|
23
24
|
# The Configuration instance used by this Initializer instance.
|
24
25
|
attr_reader :configuration
|
25
|
-
|
26
|
+
|
27
|
+
# The set of loaded plugins.
|
28
|
+
attr_reader :loaded_plugins
|
29
|
+
|
26
30
|
# Runs the initializer. By default, this will invoke the #process method,
|
27
31
|
# which simply executes all of the initialization routines. Alternately,
|
28
32
|
# you can specify explicitly which initialization routine you want:
|
@@ -40,8 +44,9 @@ module Rails
|
|
40
44
|
# instance.
|
41
45
|
def initialize(configuration)
|
42
46
|
@configuration = configuration
|
47
|
+
@loaded_plugins = Set.new
|
43
48
|
end
|
44
|
-
|
49
|
+
|
45
50
|
# Sequentially step through all of the available initialization routines,
|
46
51
|
# in order:
|
47
52
|
#
|
@@ -87,6 +92,8 @@ module Rails
|
|
87
92
|
# could overwrite anything set from the defaults/global through
|
88
93
|
# the individual base class configurations.
|
89
94
|
load_environment
|
95
|
+
|
96
|
+
load_framework_info
|
90
97
|
|
91
98
|
load_plugins
|
92
99
|
end
|
@@ -113,31 +120,24 @@ module Rails
|
|
113
120
|
configuration.frameworks.each { |framework| require(framework.to_s) }
|
114
121
|
end
|
115
122
|
|
116
|
-
# Loads
|
117
|
-
#
|
123
|
+
# Loads Rails::Version and Rails::Info.
|
124
|
+
# TODO: Make this work via dependencies.rb/const_missing instead.
|
125
|
+
def load_framework_info
|
126
|
+
require 'rails_info'
|
127
|
+
end
|
128
|
+
|
129
|
+
# Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
|
130
|
+
# defaults to <tt>vendor/plugins</tt> but may also be set to a list of
|
131
|
+
# paths, such as
|
132
|
+
# config.plugin_paths = ['lib/plugins', 'vendor/plugins']
|
118
133
|
#
|
119
|
-
#
|
120
|
-
# *
|
121
|
-
#
|
134
|
+
# Each plugin discovered in <tt>plugin_paths</tt> is initialized:
|
135
|
+
# * add its +lib+ directory, if present, to the beginning of the load path
|
136
|
+
# * evaluate <tt>init.rb</tt> if present
|
122
137
|
#
|
123
138
|
# After all plugins are loaded, duplicates are removed from the load path.
|
124
139
|
def load_plugins
|
125
|
-
|
126
|
-
|
127
|
-
Dir.glob("#{configuration.plugins_path}/*") do |directory|
|
128
|
-
next if File.basename(directory)[0] == ?. || !File.directory?(directory)
|
129
|
-
|
130
|
-
if File.directory?("#{directory}/lib")
|
131
|
-
$LOAD_PATH.unshift "#{directory}/lib"
|
132
|
-
end
|
133
|
-
|
134
|
-
if File.exist?("#{directory}/init.rb")
|
135
|
-
silence_warnings do
|
136
|
-
eval(IO.read("#{directory}/init.rb"), binding)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
140
|
+
find_plugins(configuration.plugin_paths).each { |path| load_plugin path }
|
141
141
|
$LOAD_PATH.uniq!
|
142
142
|
end
|
143
143
|
|
@@ -252,8 +252,65 @@ module Rails
|
|
252
252
|
end
|
253
253
|
end
|
254
254
|
end
|
255
|
+
|
256
|
+
protected
|
257
|
+
# Return a list of plugin paths within base_path. A plugin path is
|
258
|
+
# a directory that contains either a lib directory or an init.rb file.
|
259
|
+
# This recurses into directories which are not plugin paths, so you
|
260
|
+
# may organize your plugins which the plugin path.
|
261
|
+
def find_plugins(*base_paths)
|
262
|
+
base_paths.flatten.inject([]) do |plugins, base_path|
|
263
|
+
Dir.glob(File.join(base_path, '*')).each do |path|
|
264
|
+
if plugin_path?(path)
|
265
|
+
plugins << path
|
266
|
+
elsif File.directory?(path)
|
267
|
+
plugins += find_plugins(path)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
plugins
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
def plugin_path?(path)
|
275
|
+
File.directory?(path) and (File.directory?(File.join(path, 'lib')) or File.file?(File.join(path, 'init.rb')))
|
276
|
+
end
|
277
|
+
|
278
|
+
# Load the plugin at <tt>path</tt> unless already loaded.
|
279
|
+
#
|
280
|
+
# Each plugin is initialized:
|
281
|
+
# * add its +lib+ directory, if present, to the beginning of the load path
|
282
|
+
# * evaluate <tt>init.rb</tt> if present
|
283
|
+
#
|
284
|
+
# Returns <tt>true</tt> if the plugin is successfully loaded or
|
285
|
+
# <tt>false</tt> if it is already loaded (similar to Kernel#require).
|
286
|
+
# Raises <tt>LoadError</tt> if the plugin is not found.
|
287
|
+
def load_plugin(directory)
|
288
|
+
name = File.basename(directory)
|
289
|
+
return false if loaded_plugins.include?(name)
|
290
|
+
|
291
|
+
# Catch nonexistent and empty plugins.
|
292
|
+
raise LoadError, "No such plugin: #{directory}" unless plugin_path?(directory)
|
293
|
+
|
294
|
+
lib_path = File.join(directory, 'lib')
|
295
|
+
init_path = File.join(directory, 'init.rb')
|
296
|
+
has_lib = File.directory?(lib_path)
|
297
|
+
has_init = File.file?(init_path)
|
298
|
+
|
299
|
+
# Add lib to load path.
|
300
|
+
$LOAD_PATH.unshift(lib_path) if has_lib
|
301
|
+
|
302
|
+
# Allow plugins to reference the current configuration object
|
303
|
+
config = configuration
|
304
|
+
|
305
|
+
# Evaluate init.rb.
|
306
|
+
silence_warnings { eval(IO.read(init_path), binding) } if has_init
|
307
|
+
|
308
|
+
# Add to set of loaded plugins.
|
309
|
+
loaded_plugins << name
|
310
|
+
true
|
311
|
+
end
|
255
312
|
end
|
256
|
-
|
313
|
+
|
257
314
|
# The Configuration class holds all the parameters for the Initializer and
|
258
315
|
# ships with defaults that suites most Rails applications. But it's possible
|
259
316
|
# to overwrite everything. Usually, you'll create an Configuration file
|
@@ -331,6 +388,10 @@ module Rails
|
|
331
388
|
# any method of +nil+. Set to +false+ for the standard Ruby behavior.
|
332
389
|
attr_accessor :whiny_nils
|
333
390
|
|
391
|
+
# The path to the root of the plugins directory. By default, it is in
|
392
|
+
# <tt>vendor/plugins</tt>.
|
393
|
+
attr_accessor :plugin_paths
|
394
|
+
|
334
395
|
# Create a new Configuration instance, initialized with the default
|
335
396
|
# values.
|
336
397
|
def initialize
|
@@ -343,8 +404,9 @@ module Rails
|
|
343
404
|
self.cache_classes = default_cache_classes
|
344
405
|
self.breakpoint_server = default_breakpoint_server
|
345
406
|
self.whiny_nils = default_whiny_nils
|
407
|
+
self.plugin_paths = default_plugin_paths
|
346
408
|
self.database_configuration_file = default_database_configuration_file
|
347
|
-
|
409
|
+
|
348
410
|
for framework in default_frameworks
|
349
411
|
self.send("#{framework}=", OrderedOptions.new)
|
350
412
|
end
|
@@ -360,15 +422,9 @@ module Rails
|
|
360
422
|
# The path to the current environment's file (development.rb, etc.). By
|
361
423
|
# default the file is at <tt>config/environments/#{environment}.rb</tt>.
|
362
424
|
def environment_path
|
363
|
-
"#{
|
425
|
+
"#{root_path}/config/environments/#{environment}.rb"
|
364
426
|
end
|
365
427
|
|
366
|
-
# The path to the root of the plugins directory. By default, it is in
|
367
|
-
# <tt>vendor/plugins</tt>.
|
368
|
-
def plugins_path
|
369
|
-
"#{RAILS_ROOT}/vendor/plugins"
|
370
|
-
end
|
371
|
-
|
372
428
|
# Return the currently selected environment. By default, it returns the
|
373
429
|
# value of the +RAILS_ENV+ constant.
|
374
430
|
def environment
|
@@ -376,25 +432,30 @@ module Rails
|
|
376
432
|
end
|
377
433
|
|
378
434
|
private
|
435
|
+
def root_path
|
436
|
+
::RAILS_ROOT
|
437
|
+
end
|
438
|
+
|
379
439
|
def default_frameworks
|
380
440
|
[ :active_record, :action_controller, :action_view, :action_mailer, :action_web_service ]
|
381
441
|
end
|
382
442
|
|
383
443
|
def default_load_paths
|
384
|
-
paths = ["#{
|
444
|
+
paths = ["#{root_path}/test/mocks/#{environment}"]
|
385
445
|
|
386
446
|
# Then model subdirectories.
|
387
447
|
# TODO: Don't include .rb models as load paths
|
388
|
-
paths.concat(Dir["#{
|
389
|
-
paths.concat(Dir["#{
|
448
|
+
paths.concat(Dir["#{root_path}/app/models/[_a-z]*"])
|
449
|
+
paths.concat(Dir["#{root_path}/components/[_a-z]*"])
|
390
450
|
|
391
451
|
# Followed by the standard includes.
|
392
452
|
# TODO: Don't include dirs for frameworks that are not used
|
393
453
|
paths.concat %w(
|
394
454
|
app
|
395
455
|
app/models
|
396
|
-
app/controllers
|
397
|
-
app/helpers
|
456
|
+
app/controllers
|
457
|
+
app/helpers
|
458
|
+
app/services
|
398
459
|
app/apis
|
399
460
|
components
|
400
461
|
config
|
@@ -407,11 +468,11 @@ module Rails
|
|
407
468
|
vendor/rails/activerecord/lib
|
408
469
|
vendor/rails/actionmailer/lib
|
409
470
|
vendor/rails/actionwebservice/lib
|
410
|
-
).map { |dir| "#{
|
471
|
+
).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
|
411
472
|
end
|
412
473
|
|
413
474
|
def default_log_path
|
414
|
-
File.join(
|
475
|
+
File.join(root_path, 'log', "#{environment}.log")
|
415
476
|
end
|
416
477
|
|
417
478
|
def default_log_level
|
@@ -419,15 +480,15 @@ module Rails
|
|
419
480
|
end
|
420
481
|
|
421
482
|
def default_database_configuration_file
|
422
|
-
File.join(
|
483
|
+
File.join(root_path, 'config', 'database.yml')
|
423
484
|
end
|
424
485
|
|
425
486
|
def default_view_path
|
426
|
-
File.join(
|
487
|
+
File.join(root_path, 'app', 'views')
|
427
488
|
end
|
428
489
|
|
429
490
|
def default_controller_paths
|
430
|
-
[ File.join(
|
491
|
+
[ File.join(root_path, 'app', 'controllers'), File.join(root_path, 'components') ]
|
431
492
|
end
|
432
493
|
|
433
494
|
def default_dependency_mechanism
|
@@ -445,6 +506,10 @@ module Rails
|
|
445
506
|
def default_whiny_nils
|
446
507
|
false
|
447
508
|
end
|
509
|
+
|
510
|
+
def default_plugin_paths
|
511
|
+
["#{root_path}/vendor/plugins"]
|
512
|
+
end
|
448
513
|
end
|
449
514
|
end
|
450
515
|
|