rails 0.9.5 → 0.10.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 +46 -0
- data/README +36 -8
- data/Rakefile +18 -25
- data/bin/console +17 -30
- data/bin/console_sandbox.rb +6 -0
- data/bin/destroy +5 -0
- data/bin/generate +2 -70
- data/bin/rails +4 -28
- data/bin/server +4 -2
- data/bin/update +5 -0
- data/configs/apache.conf +7 -54
- data/configs/empty.log +0 -0
- data/configs/routes.rb +15 -0
- data/environments/shared.rb +14 -6
- data/environments/shared_for_gem.rb +12 -6
- data/fresh_rakefile +40 -8
- data/html/index.html +70 -1
- data/lib/breakpoint.rb +6 -1
- data/lib/breakpoint_client.rb +196 -193
- data/lib/dispatcher.rb +16 -38
- data/lib/rails_generator.rb +39 -198
- data/lib/rails_generator/base.rb +203 -0
- data/lib/rails_generator/commands.rb +409 -0
- data/lib/rails_generator/generators/applications/app/USAGE +16 -0
- data/lib/rails_generator/generators/applications/app/app_generator.rb +120 -0
- data/lib/rails_generator/generators/components/controller/USAGE +30 -0
- data/lib/rails_generator/generators/components/controller/controller_generator.rb +37 -0
- data/{generators → lib/rails_generator/generators/components}/controller/templates/controller.rb +1 -1
- data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +18 -0
- data/{generators → lib/rails_generator/generators/components}/controller/templates/helper.rb +0 -0
- data/{generators → lib/rails_generator/generators/components}/controller/templates/view.rhtml +0 -0
- data/lib/rails_generator/generators/components/mailer/USAGE +19 -0
- data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +32 -0
- data/{generators → lib/rails_generator/generators/components}/mailer/templates/fixture.rhtml +0 -0
- data/{generators → lib/rails_generator/generators/components}/mailer/templates/mailer.rb +0 -0
- data/{generators → lib/rails_generator/generators/components}/mailer/templates/unit_test.rb +7 -1
- data/{generators → lib/rails_generator/generators/components}/mailer/templates/view.rhtml +0 -0
- data/lib/rails_generator/generators/components/model/USAGE +17 -0
- data/lib/rails_generator/generators/components/model/model_generator.rb +18 -0
- data/{generators/scaffold → lib/rails_generator/generators/components/model}/templates/fixtures.yml +0 -2
- data/{generators → lib/rails_generator/generators/components}/model/templates/model.rb +0 -0
- data/{generators → lib/rails_generator/generators/components}/model/templates/unit_test.rb +5 -1
- data/lib/rails_generator/generators/components/scaffold/USAGE +32 -0
- data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +178 -0
- data/{generators → lib/rails_generator/generators/components}/scaffold/templates/controller.rb +1 -1
- data/lib/rails_generator/generators/components/scaffold/templates/form.rhtml +5 -0
- data/{generators → lib/rails_generator/generators/components}/scaffold/templates/functional_test.rb +7 -6
- data/lib/rails_generator/generators/components/scaffold/templates/helper.rb +2 -0
- data/{generators → lib/rails_generator/generators/components}/scaffold/templates/layout.rhtml +1 -1
- data/{generators → lib/rails_generator/generators/components}/scaffold/templates/style.css +17 -17
- data/{generators → lib/rails_generator/generators/components}/scaffold/templates/view_edit.rhtml +1 -1
- data/{generators → lib/rails_generator/generators/components}/scaffold/templates/view_list.rhtml +1 -1
- data/{generators → lib/rails_generator/generators/components}/scaffold/templates/view_new.rhtml +1 -1
- data/{generators → lib/rails_generator/generators/components}/scaffold/templates/view_show.rhtml +0 -0
- data/lib/rails_generator/lookup.rb +200 -0
- data/lib/rails_generator/manifest.rb +53 -0
- data/lib/rails_generator/options.rb +134 -0
- data/lib/rails_generator/scripts.rb +83 -0
- data/lib/rails_generator/scripts/destroy.rb +7 -0
- data/lib/rails_generator/scripts/generate.rb +7 -0
- data/lib/rails_generator/scripts/update.rb +12 -0
- data/lib/rails_generator/simple_logger.rb +46 -0
- data/lib/rails_generator/spec.rb +44 -0
- data/lib/webrick_server.rb +15 -65
- metadata +92 -48
- data/doc/apache_protection +0 -3
- data/doc/index.html +0 -70
- data/generators/controller/USAGE +0 -28
- data/generators/controller/controller_generator.rb +0 -26
- data/generators/controller/templates/functional_test.rb +0 -17
- data/generators/mailer/USAGE +0 -27
- data/generators/mailer/mailer_generator.rb +0 -22
- data/generators/model/USAGE +0 -17
- data/generators/model/model_generator.rb +0 -10
- data/generators/model/templates/fixtures.yml +0 -1
- data/generators/scaffold/USAGE +0 -27
- data/generators/scaffold/scaffold_generator.rb +0 -60
data/configs/empty.log
ADDED
File without changes
|
data/configs/routes.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
ActionController::Routing::Routes.draw do |map|
|
2
|
+
# Add your own custom routes here.
|
3
|
+
# The priority is based upon order of creation: first created -> highest priority.
|
4
|
+
|
5
|
+
# Here's a sample route:
|
6
|
+
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
|
7
|
+
# Keep in mind you can assign values other than :controller and :action
|
8
|
+
|
9
|
+
# Allow downloading Web Service WSDL as a file with an extension
|
10
|
+
# instead of a file named 'wsdl'
|
11
|
+
map.connect ':controller/service.wsdl', :action => 'wsdl'
|
12
|
+
|
13
|
+
# Install the default route as the lowest priority.
|
14
|
+
map.connect ':controller/:action/:id'
|
15
|
+
end
|
data/environments/shared.rb
CHANGED
@@ -7,6 +7,7 @@ ADDITIONAL_LOAD_PATHS = ["#{RAILS_ROOT}/test/mocks/#{RAILS_ENV}"]
|
|
7
7
|
|
8
8
|
# Then model subdirectories.
|
9
9
|
ADDITIONAL_LOAD_PATHS.concat(Dir["#{RAILS_ROOT}/app/models/[_a-z]*"])
|
10
|
+
ADDITIONAL_LOAD_PATHS.concat(Dir["#{RAILS_ROOT}/components/[_a-z]*"])
|
10
11
|
|
11
12
|
# Followed by the standard includes.
|
12
13
|
ADDITIONAL_LOAD_PATHS.concat %w(
|
@@ -14,14 +15,18 @@ ADDITIONAL_LOAD_PATHS.concat %w(
|
|
14
15
|
app/models
|
15
16
|
app/controllers
|
16
17
|
app/helpers
|
18
|
+
app/apis
|
17
19
|
config
|
20
|
+
components
|
18
21
|
lib
|
19
22
|
vendor
|
20
23
|
vendor/railties
|
21
24
|
vendor/railties/lib
|
25
|
+
vendor/activesupport/lib
|
22
26
|
vendor/activerecord/lib
|
23
27
|
vendor/actionpack/lib
|
24
28
|
vendor/actionmailer/lib
|
29
|
+
vendor/actionwebservice/lib
|
25
30
|
).map { |dir| "#{RAILS_ROOT}/#{dir}" }
|
26
31
|
|
27
32
|
# Prepend to $LOAD_PATH
|
@@ -29,9 +34,11 @@ ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(di
|
|
29
34
|
|
30
35
|
|
31
36
|
# Require Rails libraries.
|
37
|
+
require 'active_support'
|
32
38
|
require 'active_record'
|
33
39
|
require 'action_controller'
|
34
40
|
require 'action_mailer'
|
41
|
+
require 'action_web_service'
|
35
42
|
|
36
43
|
|
37
44
|
# Environment-specific configuration.
|
@@ -52,12 +59,13 @@ rescue StandardError
|
|
52
59
|
)
|
53
60
|
end
|
54
61
|
|
55
|
-
[ActiveRecord
|
56
|
-
|
57
|
-
|
58
|
-
[ActionController::Base, ActionMailer::Base].each do |klass|
|
59
|
-
klass.template_root ||= "#{RAILS_ROOT}/app/views/"
|
60
|
-
end
|
62
|
+
[ActiveRecord, ActionController, ActionMailer].each { |mod| mod::Base.logger ||= RAILS_DEFAULT_LOGGER }
|
63
|
+
[ActionController, ActionMailer].each { |mod| mod::Base.template_root ||= "#{RAILS_ROOT}/app/views/" }
|
64
|
+
ActionController::Routing::Routes.reload
|
61
65
|
|
66
|
+
Controllers = Dependencies::LoadingModule.root(
|
67
|
+
File.expand_path(File.join(RAILS_ROOT, 'app', 'controllers')),
|
68
|
+
File.expand_path(File.join(RAILS_ROOT, 'components'))
|
69
|
+
)
|
62
70
|
|
63
71
|
# Include your app's configuration here:
|
@@ -7,6 +7,7 @@ ADDITIONAL_LOAD_PATHS = ["#{RAILS_ROOT}/test/mocks/#{RAILS_ENV}"]
|
|
7
7
|
|
8
8
|
# Then model subdirectories.
|
9
9
|
ADDITIONAL_LOAD_PATHS.concat(Dir["#{RAILS_ROOT}/app/models/[_a-z]*"])
|
10
|
+
ADDITIONAL_LOAD_PATHS.concat(Dir["#{RAILS_ROOT}/components/[_a-z]*"])
|
10
11
|
|
11
12
|
# Followed by the standard includes.
|
12
13
|
ADDITIONAL_LOAD_PATHS.concat %w(
|
@@ -14,7 +15,9 @@ ADDITIONAL_LOAD_PATHS.concat %w(
|
|
14
15
|
app/models
|
15
16
|
app/controllers
|
16
17
|
app/helpers
|
18
|
+
app/apis
|
17
19
|
config
|
20
|
+
components
|
18
21
|
lib
|
19
22
|
vendor
|
20
23
|
).map { |dir| "#{RAILS_ROOT}/#{dir}" }
|
@@ -25,9 +28,11 @@ ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(di
|
|
25
28
|
|
26
29
|
# Require Rails gems.
|
27
30
|
require 'rubygems'
|
31
|
+
require_gem 'activesupport'
|
28
32
|
require_gem 'activerecord'
|
29
33
|
require_gem 'actionpack'
|
30
34
|
require_gem 'actionmailer'
|
35
|
+
require_gem 'actionwebservice'
|
31
36
|
require_gem 'rails'
|
32
37
|
|
33
38
|
|
@@ -49,12 +54,13 @@ rescue StandardError
|
|
49
54
|
)
|
50
55
|
end
|
51
56
|
|
52
|
-
[ActiveRecord
|
53
|
-
|
54
|
-
|
55
|
-
[ActionController::Base, ActionMailer::Base].each do |klass|
|
56
|
-
klass.template_root ||= "#{RAILS_ROOT}/app/views/"
|
57
|
-
end
|
57
|
+
[ActiveRecord, ActionController, ActionMailer].each { |mod| mod::Base.logger ||= RAILS_DEFAULT_LOGGER }
|
58
|
+
[ActionController, ActionMailer].each { |mod| mod::Base.template_root ||= "#{RAILS_ROOT}/app/views/" }
|
59
|
+
ActionController::Routing::Routes.reload
|
58
60
|
|
61
|
+
Controllers = Dependencies::LoadingModule.root(
|
62
|
+
File.expand_path(File.join(RAILS_ROOT, 'app', 'controllers')),
|
63
|
+
File.expand_path(File.join(RAILS_ROOT, 'components'))
|
64
|
+
)
|
59
65
|
|
60
66
|
# Include your app's configuration here:
|
data/fresh_rakefile
CHANGED
@@ -3,30 +3,61 @@ require 'rake/testtask'
|
|
3
3
|
require 'rake/rdoctask'
|
4
4
|
|
5
5
|
$VERBOSE = nil
|
6
|
-
|
7
|
-
require File.dirname(__FILE__) + '/config/environment'
|
8
|
-
require 'code_statistics'
|
6
|
+
TEST_CHANGES_SINCE = Time.now - 600
|
9
7
|
|
10
8
|
desc "Run all the tests on a fresh test database"
|
11
|
-
task :default => [ :
|
9
|
+
task :default => [ :test_units, :test_functional ]
|
10
|
+
|
11
|
+
|
12
|
+
desc 'Require application environment.'
|
13
|
+
task :environment do
|
14
|
+
unless defined? RAILS_ROOT
|
15
|
+
require File.dirname(__FILE__) + '/config/environment'
|
16
|
+
end
|
17
|
+
end
|
12
18
|
|
13
19
|
desc "Generate API documentatio, show coding stats"
|
14
20
|
task :doc => [ :appdoc, :stats ]
|
15
21
|
|
16
22
|
|
23
|
+
# Look up tests for recently modified sources.
|
24
|
+
def recent_tests(source_pattern, test_path, touched_since = 10.minutes.ago)
|
25
|
+
FileList[source_pattern].map do |path|
|
26
|
+
if File.mtime(path) > touched_since
|
27
|
+
test = "#{test_path}/#{File.basename(path, '.rb')}_test.rb"
|
28
|
+
test if File.exists?(test)
|
29
|
+
end
|
30
|
+
end.compact
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Test recent changes.'
|
34
|
+
Rake::TestTask.new(:recent => [ :clone_structure_to_test ]) do |t|
|
35
|
+
since = TEST_CHANGES_SINCE
|
36
|
+
touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } +
|
37
|
+
recent_tests('app/models/*.rb', 'test/unit', since) +
|
38
|
+
recent_tests('app/controllers/*.rb', 'test/functional', since)
|
39
|
+
|
40
|
+
t.libs << 'test'
|
41
|
+
t.verbose = true
|
42
|
+
t.test_files = touched.uniq
|
43
|
+
end
|
44
|
+
task :test_recent => [ :clone_structure_to_test ]
|
45
|
+
|
17
46
|
desc "Run the unit tests in test/unit"
|
18
47
|
Rake::TestTask.new("test_units") { |t|
|
19
48
|
t.libs << "test"
|
20
|
-
t.pattern = 'test/unit
|
49
|
+
t.pattern = 'test/unit/**/*_test.rb'
|
21
50
|
t.verbose = true
|
22
51
|
}
|
52
|
+
task :test_units => [ :clone_structure_to_test ]
|
23
53
|
|
24
54
|
desc "Run the functional tests in test/functional"
|
25
55
|
Rake::TestTask.new("test_functional") { |t|
|
26
56
|
t.libs << "test"
|
27
|
-
t.pattern = 'test/functional
|
57
|
+
t.pattern = 'test/functional/**/*_test.rb'
|
28
58
|
t.verbose = true
|
29
59
|
}
|
60
|
+
task :test_functional => [ :clone_structure_to_test ]
|
30
61
|
|
31
62
|
desc "Generate documentation for the application"
|
32
63
|
Rake::RDocTask.new("appdoc") { |rdoc|
|
@@ -62,6 +93,7 @@ Rake::RDocTask.new("apidoc") { |rdoc|
|
|
62
93
|
|
63
94
|
desc "Report code statistics (KLOCs, etc) from the application"
|
64
95
|
task :stats do
|
96
|
+
require 'code_statistics'
|
65
97
|
CodeStatistics.new(
|
66
98
|
["Helpers", "app/helpers"],
|
67
99
|
["Controllers", "app/controllers"],
|
@@ -91,7 +123,7 @@ task :clone_structure_to_test => [ :db_structure_dump, :purge_test_database ] do
|
|
91
123
|
end
|
92
124
|
|
93
125
|
desc "Dump the database structure to a SQL file"
|
94
|
-
task :db_structure_dump do
|
126
|
+
task :db_structure_dump => :environment do
|
95
127
|
abcs = ActiveRecord::Base.configurations
|
96
128
|
case abcs[RAILS_ENV]["adapter"]
|
97
129
|
when "mysql"
|
@@ -107,7 +139,7 @@ task :db_structure_dump do
|
|
107
139
|
end
|
108
140
|
|
109
141
|
desc "Empty the test database"
|
110
|
-
task :purge_test_database do
|
142
|
+
task :purge_test_database => :environment do
|
111
143
|
abcs = ActiveRecord::Base.configurations
|
112
144
|
case abcs["test"]["adapter"]
|
113
145
|
when "mysql"
|
data/html/index.html
CHANGED
@@ -1 +1,70 @@
|
|
1
|
-
<html
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Rails: Welcome on board</title>
|
4
|
+
<style>
|
5
|
+
body { background-color: #fff; color: #333; }
|
6
|
+
|
7
|
+
body, p, ol, ul, td {
|
8
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
9
|
+
font-size: 12px;
|
10
|
+
line-height: 18px;
|
11
|
+
}
|
12
|
+
|
13
|
+
li {
|
14
|
+
margin-bottom: 7px;
|
15
|
+
}
|
16
|
+
|
17
|
+
pre {
|
18
|
+
background-color: #eee;
|
19
|
+
padding: 10px;
|
20
|
+
font-size: 11px;
|
21
|
+
}
|
22
|
+
|
23
|
+
a { color: #000; }
|
24
|
+
a:visited { color: #666; }
|
25
|
+
a:hover { color: #fff; background-color:#000; }
|
26
|
+
</style>
|
27
|
+
</head>
|
28
|
+
<body>
|
29
|
+
|
30
|
+
<h1>Congratulations, you've put Ruby on Rails!</h1>
|
31
|
+
|
32
|
+
<p><b>Before you move on</b>, verify that the following conditions have been met:</p>
|
33
|
+
|
34
|
+
<ol>
|
35
|
+
<li>The log and public directories must be writable to the web server (<code>chmod -R 775 log</code> and <code>chmod -R 775 public</code>).
|
36
|
+
<li>
|
37
|
+
The shebang line in the public/dispatch* files must reference your Ruby installation. <br/>
|
38
|
+
You might need to change it to <code>#!/usr/bin/env ruby</code> or point directly at the installation.
|
39
|
+
</li>
|
40
|
+
<li>
|
41
|
+
Rails on Apache needs to have the cgi handler and mod_rewrite enabled. <br/>
|
42
|
+
Somewhere in your httpd.conf, you should have:<br/>
|
43
|
+
<code>AddHandler cgi-script .cgi</code><br/>
|
44
|
+
<code>LoadModule rewrite_module libexec/httpd/mod_rewrite.so</code><br/>
|
45
|
+
<code>AddModule mod_rewrite.c</code>
|
46
|
+
</li>
|
47
|
+
</ol>
|
48
|
+
|
49
|
+
<p>Take the following steps to get started:</p>
|
50
|
+
|
51
|
+
<ol>
|
52
|
+
<li>Create empty development and test databases for your application.<br/>
|
53
|
+
<small>Recommendation: Use *_development and *_test names, such as basecamp_development and basecamp_test</small><br/>
|
54
|
+
<small>Warning: Don't point your test database at your development database, it'll destroy the latter on test runs!</small>
|
55
|
+
<li>Edit config/database.yml with your database settings.
|
56
|
+
<li>Create controllers and models using the generator in <code>script/generate</code> <br/>
|
57
|
+
<small>Help: Run the generator with no arguments for documentation</small>
|
58
|
+
<li>See all the tests run by running <code>rake</code>.
|
59
|
+
<li>Develop your Rails application!
|
60
|
+
<li>Setup Apache with <a href="http://www.fastcgi.com">FastCGI</a> (and <a href="http://raa.ruby-lang.org/list.rhtml?name=fcgi">Ruby bindings</a>), if you need better performance
|
61
|
+
</ol>
|
62
|
+
|
63
|
+
<p>
|
64
|
+
Having problems getting up and running? First try debugging it yourself by looking at the log files. <br/>
|
65
|
+
Then try the friendly Rails community <a href="http://www.rubyonrails.org">on the web</a> or <a href="http://www.rubyonrails.org/show/IRC">on IRC</a>
|
66
|
+
(<a href="irc://irc.freenode.net/#rubyonrails">FreeNode#rubyonrails</a>).
|
67
|
+
</p>
|
68
|
+
|
69
|
+
</body>
|
70
|
+
</html>
|
data/lib/breakpoint.rb
CHANGED
@@ -21,7 +21,7 @@ require 'drb'
|
|
21
21
|
require 'drb/acl'
|
22
22
|
|
23
23
|
module Breakpoint
|
24
|
-
id = %q$Id: breakpoint.rb
|
24
|
+
id = %q$Id: breakpoint.rb 92 2005-02-04 22:35:53Z flgr $
|
25
25
|
Version = id.split(" ")[2].to_i
|
26
26
|
|
27
27
|
extend self
|
@@ -122,6 +122,7 @@ module Breakpoint
|
|
122
122
|
# in the context of the client.
|
123
123
|
class Client
|
124
124
|
def initialize(eval_handler) # :nodoc:
|
125
|
+
eval_handler.untaint
|
125
126
|
@eval_handler = eval_handler
|
126
127
|
end
|
127
128
|
|
@@ -288,6 +289,8 @@ module Breakpoint
|
|
288
289
|
def collision
|
289
290
|
sleep(0.5) until @collision_handler
|
290
291
|
|
292
|
+
@collision_handler.untaint
|
293
|
+
|
291
294
|
@collision_handler.call
|
292
295
|
end
|
293
296
|
|
@@ -299,6 +302,7 @@ module Breakpoint
|
|
299
302
|
|
300
303
|
sleep(0.5) until @handler
|
301
304
|
|
305
|
+
@handler.untaint
|
302
306
|
@handler.call(workspace, message)
|
303
307
|
end
|
304
308
|
|
@@ -456,6 +460,7 @@ module IRB # :nodoc:
|
|
456
460
|
old_CurrentContext
|
457
461
|
end
|
458
462
|
end
|
463
|
+
def IRB.parse_opts() end
|
459
464
|
|
460
465
|
class Context
|
461
466
|
alias :old_evaluate :evaluate
|
data/lib/breakpoint_client.rb
CHANGED
@@ -1,193 +1,196 @@
|
|
1
|
-
require 'breakpoint'
|
2
|
-
require 'optparse'
|
3
|
-
require 'timeout'
|
4
|
-
|
5
|
-
Options = {
|
6
|
-
:ClientURI => nil,
|
7
|
-
:ServerURI => "druby://localhost:42531",
|
8
|
-
:RetryDelay =>
|
9
|
-
:Permanent => true,
|
10
|
-
:Verbose => false
|
11
|
-
}
|
12
|
-
|
13
|
-
ARGV.options do |opts|
|
14
|
-
script_name = File.basename($0)
|
15
|
-
opts.banner = [
|
16
|
-
"Usage: ruby #{script_name} [Options] [server uri]",
|
17
|
-
"",
|
18
|
-
"This tool lets you connect to a breakpoint service ",
|
19
|
-
"which was started via Breakpoint.activate_drb.",
|
20
|
-
"",
|
21
|
-
"The server uri defaults to druby://localhost:42531"
|
22
|
-
].join("\n")
|
23
|
-
|
24
|
-
opts.separator ""
|
25
|
-
|
26
|
-
opts.on("-c", "--client-uri=uri",
|
27
|
-
"Run the client on the specified uri.",
|
28
|
-
"This can be used to specify the port",
|
29
|
-
"that the client uses to allow for back",
|
30
|
-
"connections from the server.",
|
31
|
-
"Default: Find a good URI automatically.",
|
32
|
-
"Example: -c druby://localhost:12345"
|
33
|
-
) { |Options[:ClientURI]| }
|
34
|
-
|
35
|
-
opts.on("-s", "--server-uri=uri",
|
36
|
-
"Connect to the server specified at the",
|
37
|
-
"specified uri.",
|
38
|
-
"Default: druby://localhost:42531"
|
39
|
-
) { |Options[:ServerURI]| }
|
40
|
-
|
41
|
-
opts.on("-R", "--retry-delay=delay", Integer,
|
42
|
-
"Automatically try to reconnect to the",
|
43
|
-
"server after delay seconds when the",
|
44
|
-
"connection failed or timed out.",
|
45
|
-
"A value of 0 disables automatical",
|
46
|
-
"reconnecting completely.",
|
47
|
-
"Default: 10"
|
48
|
-
) { |Options[:RetryDelay]| }
|
49
|
-
|
50
|
-
opts.on("-P", "--[no-]permanent",
|
51
|
-
"Run the breakpoint client in permanent mode.",
|
52
|
-
"This means that the client will keep continue",
|
53
|
-
"running even after the server has closed the",
|
54
|
-
"connection. Useful for example in Rails."
|
55
|
-
) { |Options[:Permanent]| }
|
56
|
-
|
57
|
-
opts.on("-V", "--[no-]verbose",
|
58
|
-
"Run the breakpoint client in verbose mode.",
|
59
|
-
"Will produce more messages, for example between",
|
60
|
-
"individual breakpoints. This might help in seeing",
|
61
|
-
"that the breakpoint client is still alive, but adds",
|
62
|
-
"quite a bit of clutter."
|
63
|
-
) { |Options[:Verbose]| }
|
64
|
-
|
65
|
-
opts.separator ""
|
66
|
-
|
67
|
-
opts.on("-h", "--help",
|
68
|
-
"Show this help message."
|
69
|
-
) { puts opts; exit }
|
70
|
-
opts.on("-v", "--version",
|
71
|
-
"Display the version information."
|
72
|
-
) do
|
73
|
-
id = %q$Id: breakpoint_client.rb
|
74
|
-
puts id.sub("Id: ", "")
|
75
|
-
puts "(Breakpoint::Version = #{Breakpoint::Version})"
|
76
|
-
exit
|
77
|
-
end
|
78
|
-
|
79
|
-
opts.parse!
|
80
|
-
end
|
81
|
-
|
82
|
-
Options[:ServerURI] = ARGV[0] if ARGV[0]
|
83
|
-
|
84
|
-
module Handlers
|
85
|
-
extend self
|
86
|
-
|
87
|
-
def breakpoint_handler(workspace, message)
|
88
|
-
puts message
|
89
|
-
IRB.start(nil, nil, workspace)
|
90
|
-
|
91
|
-
puts ""
|
92
|
-
if Options[:Verbose] then
|
93
|
-
puts "Resumed execution. Waiting for next breakpoint...", ""
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def eval_handler(code)
|
98
|
-
result = eval(code, TOPLEVEL_BINDING)
|
99
|
-
if result then
|
100
|
-
DRbObject.new(result)
|
101
|
-
else
|
102
|
-
result
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def collision_handler()
|
107
|
-
msg = [
|
108
|
-
" *** Breakpoint service collision ***",
|
109
|
-
" Another Breakpoint service tried to use the",
|
110
|
-
" port already occupied by this one. It will",
|
111
|
-
" keep waiting until this Breakpoint service",
|
112
|
-
" is shut down.",
|
113
|
-
" ",
|
114
|
-
" If you are using the Breakpoint library for",
|
115
|
-
" debugging a Rails or other CGI application",
|
116
|
-
" this likely means that this Breakpoint",
|
117
|
-
" session belongs to an earlier, outdated",
|
118
|
-
" request and should be shut down via 'exit'."
|
119
|
-
].join("\n")
|
120
|
-
|
121
|
-
if RUBY_PLATFORM["win"] then
|
122
|
-
# This sucks. Sorry, I'm not doing this because
|
123
|
-
# I like funky message boxes -- I need to do this
|
124
|
-
# because on Windows I have no way of displaying
|
125
|
-
# my notification via puts() when gets() is still
|
126
|
-
# being performed on STDIN. I have not found a
|
127
|
-
# better solution.
|
128
|
-
begin
|
129
|
-
require 'tk'
|
130
|
-
root = TkRoot.new { withdraw }
|
131
|
-
Tk.messageBox('message' => msg, 'type' => 'ok')
|
132
|
-
root.destroy
|
133
|
-
rescue Exception
|
134
|
-
puts "", msg, ""
|
135
|
-
end
|
136
|
-
else
|
137
|
-
puts "", msg, ""
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
# Used for checking whether we are currently in the reconnecting loop.
|
143
|
-
reconnecting = false
|
144
|
-
|
145
|
-
loop do
|
146
|
-
DRb.start_service(Options[:ClientURI])
|
147
|
-
|
148
|
-
begin
|
149
|
-
service = DRbObject.new(nil, Options[:ServerURI])
|
150
|
-
|
151
|
-
begin
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
puts "
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
1
|
+
require 'breakpoint'
|
2
|
+
require 'optparse'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
Options = {
|
6
|
+
:ClientURI => nil,
|
7
|
+
:ServerURI => "druby://localhost:42531",
|
8
|
+
:RetryDelay => 2,
|
9
|
+
:Permanent => true,
|
10
|
+
:Verbose => false
|
11
|
+
}
|
12
|
+
|
13
|
+
ARGV.options do |opts|
|
14
|
+
script_name = File.basename($0)
|
15
|
+
opts.banner = [
|
16
|
+
"Usage: ruby #{script_name} [Options] [server uri]",
|
17
|
+
"",
|
18
|
+
"This tool lets you connect to a breakpoint service ",
|
19
|
+
"which was started via Breakpoint.activate_drb.",
|
20
|
+
"",
|
21
|
+
"The server uri defaults to druby://localhost:42531"
|
22
|
+
].join("\n")
|
23
|
+
|
24
|
+
opts.separator ""
|
25
|
+
|
26
|
+
opts.on("-c", "--client-uri=uri",
|
27
|
+
"Run the client on the specified uri.",
|
28
|
+
"This can be used to specify the port",
|
29
|
+
"that the client uses to allow for back",
|
30
|
+
"connections from the server.",
|
31
|
+
"Default: Find a good URI automatically.",
|
32
|
+
"Example: -c druby://localhost:12345"
|
33
|
+
) { |Options[:ClientURI]| }
|
34
|
+
|
35
|
+
opts.on("-s", "--server-uri=uri",
|
36
|
+
"Connect to the server specified at the",
|
37
|
+
"specified uri.",
|
38
|
+
"Default: druby://localhost:42531"
|
39
|
+
) { |Options[:ServerURI]| }
|
40
|
+
|
41
|
+
opts.on("-R", "--retry-delay=delay", Integer,
|
42
|
+
"Automatically try to reconnect to the",
|
43
|
+
"server after delay seconds when the",
|
44
|
+
"connection failed or timed out.",
|
45
|
+
"A value of 0 disables automatical",
|
46
|
+
"reconnecting completely.",
|
47
|
+
"Default: 10"
|
48
|
+
) { |Options[:RetryDelay]| }
|
49
|
+
|
50
|
+
opts.on("-P", "--[no-]permanent",
|
51
|
+
"Run the breakpoint client in permanent mode.",
|
52
|
+
"This means that the client will keep continue",
|
53
|
+
"running even after the server has closed the",
|
54
|
+
"connection. Useful for example in Rails."
|
55
|
+
) { |Options[:Permanent]| }
|
56
|
+
|
57
|
+
opts.on("-V", "--[no-]verbose",
|
58
|
+
"Run the breakpoint client in verbose mode.",
|
59
|
+
"Will produce more messages, for example between",
|
60
|
+
"individual breakpoints. This might help in seeing",
|
61
|
+
"that the breakpoint client is still alive, but adds",
|
62
|
+
"quite a bit of clutter."
|
63
|
+
) { |Options[:Verbose]| }
|
64
|
+
|
65
|
+
opts.separator ""
|
66
|
+
|
67
|
+
opts.on("-h", "--help",
|
68
|
+
"Show this help message."
|
69
|
+
) { puts opts; exit }
|
70
|
+
opts.on("-v", "--version",
|
71
|
+
"Display the version information."
|
72
|
+
) do
|
73
|
+
id = %q$Id: breakpoint_client.rb 91 2005-02-04 22:34:08Z flgr $
|
74
|
+
puts id.sub("Id: ", "")
|
75
|
+
puts "(Breakpoint::Version = #{Breakpoint::Version})"
|
76
|
+
exit
|
77
|
+
end
|
78
|
+
|
79
|
+
opts.parse!
|
80
|
+
end
|
81
|
+
|
82
|
+
Options[:ServerURI] = ARGV[0] if ARGV[0]
|
83
|
+
|
84
|
+
module Handlers
|
85
|
+
extend self
|
86
|
+
|
87
|
+
def breakpoint_handler(workspace, message)
|
88
|
+
puts message
|
89
|
+
IRB.start(nil, nil, workspace)
|
90
|
+
|
91
|
+
puts ""
|
92
|
+
if Options[:Verbose] then
|
93
|
+
puts "Resumed execution. Waiting for next breakpoint...", ""
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def eval_handler(code)
|
98
|
+
result = eval(code, TOPLEVEL_BINDING)
|
99
|
+
if result then
|
100
|
+
DRbObject.new(result)
|
101
|
+
else
|
102
|
+
result
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def collision_handler()
|
107
|
+
msg = [
|
108
|
+
" *** Breakpoint service collision ***",
|
109
|
+
" Another Breakpoint service tried to use the",
|
110
|
+
" port already occupied by this one. It will",
|
111
|
+
" keep waiting until this Breakpoint service",
|
112
|
+
" is shut down.",
|
113
|
+
" ",
|
114
|
+
" If you are using the Breakpoint library for",
|
115
|
+
" debugging a Rails or other CGI application",
|
116
|
+
" this likely means that this Breakpoint",
|
117
|
+
" session belongs to an earlier, outdated",
|
118
|
+
" request and should be shut down via 'exit'."
|
119
|
+
].join("\n")
|
120
|
+
|
121
|
+
if RUBY_PLATFORM["win"] then
|
122
|
+
# This sucks. Sorry, I'm not doing this because
|
123
|
+
# I like funky message boxes -- I need to do this
|
124
|
+
# because on Windows I have no way of displaying
|
125
|
+
# my notification via puts() when gets() is still
|
126
|
+
# being performed on STDIN. I have not found a
|
127
|
+
# better solution.
|
128
|
+
begin
|
129
|
+
require 'tk'
|
130
|
+
root = TkRoot.new { withdraw }
|
131
|
+
Tk.messageBox('message' => msg, 'type' => 'ok')
|
132
|
+
root.destroy
|
133
|
+
rescue Exception
|
134
|
+
puts "", msg, ""
|
135
|
+
end
|
136
|
+
else
|
137
|
+
puts "", msg, ""
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Used for checking whether we are currently in the reconnecting loop.
|
143
|
+
reconnecting = false
|
144
|
+
|
145
|
+
loop do
|
146
|
+
DRb.start_service(Options[:ClientURI])
|
147
|
+
|
148
|
+
begin
|
149
|
+
service = DRbObject.new(nil, Options[:ServerURI])
|
150
|
+
|
151
|
+
begin
|
152
|
+
ehandler = Handlers.method(:eval_handler)
|
153
|
+
chandler = Handlers.method(:collision_handler)
|
154
|
+
handler = Handlers.method(:breakpoint_handler)
|
155
|
+
service.eval_handler = ehandler
|
156
|
+
service.collision_handler = chandler
|
157
|
+
service.handler = handler
|
158
|
+
|
159
|
+
reconnecting = false
|
160
|
+
if Options[:Verbose] then
|
161
|
+
puts "Connection established. Waiting for breakpoint...", ""
|
162
|
+
end
|
163
|
+
|
164
|
+
loop do
|
165
|
+
begin
|
166
|
+
service.ping
|
167
|
+
rescue DRb::DRbConnError => error
|
168
|
+
puts "Server exited. Closing connection...", ""
|
169
|
+
exit! unless Options[:Permanent]
|
170
|
+
break
|
171
|
+
end
|
172
|
+
|
173
|
+
sleep(0.5)
|
174
|
+
end
|
175
|
+
ensure
|
176
|
+
service.eval_handler = nil
|
177
|
+
service.collision_handler = nil
|
178
|
+
service.handler = nil
|
179
|
+
end
|
180
|
+
rescue Exception => error
|
181
|
+
if Options[:RetryDelay] > 0 then
|
182
|
+
if not reconnecting then
|
183
|
+
reconnecting = true
|
184
|
+
puts "No connection to breakpoint service at #{Options[:ServerURI]} " +
|
185
|
+
"(#{error.class})"
|
186
|
+
puts error.backtrace if $DEBUG
|
187
|
+
puts "Tries to connect will be made every #{Options[:RetryDelay]} seconds..."
|
188
|
+
end
|
189
|
+
|
190
|
+
sleep Options[:RetryDelay]
|
191
|
+
retry
|
192
|
+
else
|
193
|
+
raise
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|