steamcannon-thin 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. data/CHANGELOG +288 -0
  2. data/COPYING +18 -0
  3. data/README +69 -0
  4. data/Rakefile +44 -0
  5. data/benchmark/abc +51 -0
  6. data/benchmark/benchmarker.rb +80 -0
  7. data/benchmark/runner +82 -0
  8. data/bin/thin +6 -0
  9. data/example/adapter.rb +32 -0
  10. data/example/async_app.ru +126 -0
  11. data/example/async_chat.ru +247 -0
  12. data/example/async_tailer.ru +100 -0
  13. data/example/config.ru +22 -0
  14. data/example/monit_sockets +20 -0
  15. data/example/monit_unixsock +20 -0
  16. data/example/myapp.rb +1 -0
  17. data/example/ramaze.ru +12 -0
  18. data/example/thin.god +80 -0
  19. data/example/thin_solaris_smf.erb +36 -0
  20. data/example/thin_solaris_smf.readme.txt +150 -0
  21. data/example/vlad.rake +64 -0
  22. data/ext/thin_parser/common.rl +55 -0
  23. data/ext/thin_parser/ext_help.h +14 -0
  24. data/ext/thin_parser/extconf.rb +6 -0
  25. data/ext/thin_parser/parser.c +1249 -0
  26. data/ext/thin_parser/parser.h +49 -0
  27. data/ext/thin_parser/parser.rl +157 -0
  28. data/ext/thin_parser/thin.c +436 -0
  29. data/lib/rack/adapter/loader.rb +91 -0
  30. data/lib/rack/adapter/rails.rb +183 -0
  31. data/lib/thin.rb +56 -0
  32. data/lib/thin/backends/base.rb +149 -0
  33. data/lib/thin/backends/swiftiply_client.rb +56 -0
  34. data/lib/thin/backends/tcp_server.rb +29 -0
  35. data/lib/thin/backends/unix_server.rb +51 -0
  36. data/lib/thin/command.rb +53 -0
  37. data/lib/thin/connection.rb +224 -0
  38. data/lib/thin/controllers/cluster.rb +178 -0
  39. data/lib/thin/controllers/controller.rb +188 -0
  40. data/lib/thin/controllers/service.rb +75 -0
  41. data/lib/thin/controllers/service.sh.erb +39 -0
  42. data/lib/thin/daemonizing.rb +180 -0
  43. data/lib/thin/headers.rb +39 -0
  44. data/lib/thin/logging.rb +54 -0
  45. data/lib/thin/request.rb +156 -0
  46. data/lib/thin/response.rb +101 -0
  47. data/lib/thin/runner.rb +220 -0
  48. data/lib/thin/server.rb +253 -0
  49. data/lib/thin/stats.html.erb +216 -0
  50. data/lib/thin/stats.rb +52 -0
  51. data/lib/thin/statuses.rb +43 -0
  52. data/lib/thin/version.rb +32 -0
  53. data/lib/thin_parser.so +0 -0
  54. data/spec/backends/swiftiply_client_spec.rb +66 -0
  55. data/spec/backends/tcp_server_spec.rb +33 -0
  56. data/spec/backends/unix_server_spec.rb +37 -0
  57. data/spec/command_spec.rb +25 -0
  58. data/spec/configs/cluster.yml +9 -0
  59. data/spec/configs/single.yml +9 -0
  60. data/spec/connection_spec.rb +106 -0
  61. data/spec/controllers/cluster_spec.rb +267 -0
  62. data/spec/controllers/controller_spec.rb +129 -0
  63. data/spec/controllers/service_spec.rb +50 -0
  64. data/spec/daemonizing_spec.rb +196 -0
  65. data/spec/headers_spec.rb +40 -0
  66. data/spec/logging_spec.rb +46 -0
  67. data/spec/perf/request_perf_spec.rb +50 -0
  68. data/spec/perf/response_perf_spec.rb +19 -0
  69. data/spec/perf/server_perf_spec.rb +39 -0
  70. data/spec/rack/loader_spec.rb +42 -0
  71. data/spec/rack/rails_adapter_spec.rb +173 -0
  72. data/spec/rails_app/app/controllers/application.rb +10 -0
  73. data/spec/rails_app/app/controllers/simple_controller.rb +19 -0
  74. data/spec/rails_app/app/helpers/application_helper.rb +3 -0
  75. data/spec/rails_app/app/views/simple/index.html.erb +15 -0
  76. data/spec/rails_app/config/boot.rb +109 -0
  77. data/spec/rails_app/config/environment.rb +64 -0
  78. data/spec/rails_app/config/environments/development.rb +18 -0
  79. data/spec/rails_app/config/environments/production.rb +19 -0
  80. data/spec/rails_app/config/environments/test.rb +22 -0
  81. data/spec/rails_app/config/initializers/inflections.rb +10 -0
  82. data/spec/rails_app/config/initializers/mime_types.rb +5 -0
  83. data/spec/rails_app/config/routes.rb +35 -0
  84. data/spec/rails_app/public/404.html +30 -0
  85. data/spec/rails_app/public/422.html +30 -0
  86. data/spec/rails_app/public/500.html +30 -0
  87. data/spec/rails_app/public/dispatch.cgi +10 -0
  88. data/spec/rails_app/public/dispatch.fcgi +24 -0
  89. data/spec/rails_app/public/dispatch.rb +10 -0
  90. data/spec/rails_app/public/favicon.ico +0 -0
  91. data/spec/rails_app/public/images/rails.png +0 -0
  92. data/spec/rails_app/public/index.html +277 -0
  93. data/spec/rails_app/public/javascripts/application.js +2 -0
  94. data/spec/rails_app/public/javascripts/controls.js +963 -0
  95. data/spec/rails_app/public/javascripts/dragdrop.js +972 -0
  96. data/spec/rails_app/public/javascripts/effects.js +1120 -0
  97. data/spec/rails_app/public/javascripts/prototype.js +4225 -0
  98. data/spec/rails_app/public/robots.txt +5 -0
  99. data/spec/rails_app/script/about +3 -0
  100. data/spec/rails_app/script/console +3 -0
  101. data/spec/rails_app/script/destroy +3 -0
  102. data/spec/rails_app/script/generate +3 -0
  103. data/spec/rails_app/script/performance/benchmarker +3 -0
  104. data/spec/rails_app/script/performance/profiler +3 -0
  105. data/spec/rails_app/script/performance/request +3 -0
  106. data/spec/rails_app/script/plugin +3 -0
  107. data/spec/rails_app/script/process/inspector +3 -0
  108. data/spec/rails_app/script/process/reaper +3 -0
  109. data/spec/rails_app/script/process/spawner +3 -0
  110. data/spec/rails_app/script/runner +3 -0
  111. data/spec/rails_app/script/server +3 -0
  112. data/spec/request/mongrel_spec.rb +39 -0
  113. data/spec/request/parser_spec.rb +254 -0
  114. data/spec/request/persistent_spec.rb +35 -0
  115. data/spec/request/processing_spec.rb +50 -0
  116. data/spec/response_spec.rb +91 -0
  117. data/spec/runner_spec.rb +168 -0
  118. data/spec/server/builder_spec.rb +44 -0
  119. data/spec/server/pipelining_spec.rb +110 -0
  120. data/spec/server/robustness_spec.rb +34 -0
  121. data/spec/server/stopping_spec.rb +55 -0
  122. data/spec/server/swiftiply.yml +6 -0
  123. data/spec/server/swiftiply_spec.rb +32 -0
  124. data/spec/server/tcp_spec.rb +57 -0
  125. data/spec/server/threaded_spec.rb +27 -0
  126. data/spec/server/unix_socket_spec.rb +26 -0
  127. data/spec/server_spec.rb +100 -0
  128. data/spec/spec_helper.rb +220 -0
  129. data/tasks/announce.rake +22 -0
  130. data/tasks/deploy.rake +13 -0
  131. data/tasks/email.erb +30 -0
  132. data/tasks/gem.rake +66 -0
  133. data/tasks/rdoc.rake +25 -0
  134. data/tasks/site.rake +15 -0
  135. data/tasks/spec.rake +43 -0
  136. data/tasks/stats.rake +28 -0
  137. metadata +251 -0
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Request, 'performance' do
4
+ it "should be faster then #{max_parsing_time = 0.0002} RubySeconds" do
5
+ body = <<-EOS.chomp.gsub("\n", "\r\n")
6
+ POST /postit HTTP/1.1
7
+ Host: localhost:3000
8
+ User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9
9
+ Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
10
+ Accept-Language: en-us,en;q=0.5
11
+ Accept-Encoding: gzip,deflate
12
+ Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
13
+ Keep-Alive: 300
14
+ Connection: keep-alive
15
+ Content-Type: text/html
16
+ Content-Length: 37
17
+
18
+ hi=there&name=marc&email=macournoyer@gmail.com
19
+ EOS
20
+
21
+ proc { R(body) }.should be_faster_then(max_parsing_time)
22
+ end
23
+
24
+ it 'should be comparable to Mongrel parser' do
25
+ require 'http11'
26
+
27
+ body = <<-EOS.chomp.gsub("\n", "\r\n")
28
+ POST /postit HTTP/1.1
29
+ Host: localhost:3000
30
+ User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9
31
+ Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
32
+ Accept-Language: en-us,en;q=0.5
33
+ Accept-Encoding: gzip,deflate
34
+ Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
35
+ Keep-Alive: 300
36
+ Connection: keep-alive
37
+ Content-Type: text/html
38
+ Content-Length: 37
39
+
40
+ hi=there&name=marc&email=macournoyer@gmail.com
41
+ EOS
42
+
43
+ tests = 10_000
44
+ puts
45
+ Benchmark.bmbm(10) do |results|
46
+ results.report("mongrel:") { tests.times { Mongrel::HttpParser.new.execute({}, body.dup, 0) } }
47
+ results.report("thin:") { tests.times { Thin::HttpParser.new.execute({'rack.input' => StringIO.new}, body.dup, 0) } }
48
+ end
49
+ end if ENV['BM']
50
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Response, 'performance' do
4
+ before do
5
+ @response = Response.new
6
+ @response.body = ''
7
+ end
8
+
9
+ it "should be fast" do
10
+ @response.body << <<-EOS
11
+ <html><head><title>Dir listing</title></head>
12
+ <body><h1>Listing stuff</h1><ul>
13
+ #{'<li>Hi!</li>' * 100}
14
+ </ul></body></html>
15
+ EOS
16
+
17
+ proc { @response.each { |l| l } }.should be_faster_then(0.00011)
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Server, 'performance' do
4
+ before do
5
+ start_server do |env|
6
+ body = env.inspect + env['rack.input'].read
7
+ [200, { 'Content-Length' => body.size.to_s }, body]
8
+ end
9
+ end
10
+
11
+ it "should handle GET in less then #{get_request_time = 0.0045} RubySecond" do
12
+ proc { get('/') }.should be_faster_then(get_request_time)
13
+ end
14
+
15
+ it "should handle POST in less then #{post_request_time = 0.007} RubySecond" do
16
+ proc { post('/', :file => 'X' * 1000) }.should be_faster_then(post_request_time)
17
+ end
18
+
19
+ after do
20
+ stop_server
21
+ end
22
+ end
23
+
24
+ describe Server, 'UNIX socket performance' do
25
+ before do
26
+ start_server('/tmp/thin_test.sock') do |env|
27
+ body = env.inspect + env['rack.input'].read
28
+ [200, { 'Content-Length' => body.size.to_s }, body]
29
+ end
30
+ end
31
+
32
+ it "should handle GET in less then #{get_request_time = 0.002} RubySecond" do
33
+ proc { get('/') }.should be_faster_then(get_request_time)
34
+ end
35
+
36
+ after do
37
+ stop_server
38
+ end
39
+ end
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Rack::Adapter do
4
+ before do
5
+ @config_ru_path = File.dirname(__FILE__) + '/../../example'
6
+ @rails_path = File.dirname(__FILE__) + '/../rails_app'
7
+ end
8
+
9
+ it "should load Rack app from config" do
10
+ Rack::Adapter.load(@config_ru_path + '/config.ru').class.should == Proc
11
+ end
12
+
13
+ it "should guess Rack app from dir" do
14
+ Rack::Adapter.guess(@config_ru_path).should == :rack
15
+ end
16
+
17
+ it "should guess rails app from dir" do
18
+ Rack::Adapter.guess(@rails_path).should == :rails
19
+ end
20
+
21
+ it "should return nil when can't guess from dir" do
22
+ proc { Rack::Adapter.guess('.') }.should raise_error(Rack::AdapterNotFound)
23
+ end
24
+
25
+ it "should load Rack adapter" do
26
+ Rack::Adapter.for(:rack, :chdir => @config_ru_path).class.should == Proc
27
+ end
28
+
29
+ it "should load Rails adapter" do
30
+ Rack::Adapter::Rails.should_receive(:new)
31
+ Rack::Adapter.for(:rails, :chdir => @rails_path)
32
+ end
33
+
34
+ it "should load File adapter" do
35
+ Rack::File.should_receive(:new)
36
+ Rack::Adapter.for(:file)
37
+ end
38
+
39
+ it "should raise error when adapter can't be found" do
40
+ proc { Rack::Adapter.for(:fart, {}) }.should raise_error(Rack::AdapterNotFound)
41
+ end
42
+ end
@@ -0,0 +1,173 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'rack/mock'
3
+
4
+ begin
5
+ gem 'rails', '= 2.0.2' # We could freeze Rails in the rails_app dir to remove this
6
+
7
+ describe Rack::Adapter::Rails do
8
+ before do
9
+ @rails_app_path = File.dirname(__FILE__) + '/../rails_app'
10
+ @request = Rack::MockRequest.new(Rack::Adapter::Rails.new(:root => @rails_app_path))
11
+ end
12
+
13
+ it "should handle simple GET request" do
14
+ res = @request.get("/simple", :lint => true)
15
+
16
+ res.should be_ok
17
+ res["Content-Type"].should include("text/html")
18
+
19
+ res.body.should include('Simple#index')
20
+ end
21
+
22
+ it "should handle POST parameters" do
23
+ data = "foo=bar"
24
+ res = @request.post("/simple/post_form", :input => data, 'CONTENT_LENGTH' => data.size.to_s, :lint => true)
25
+
26
+ res.should be_ok
27
+ res["Content-Type"].should include("text/html")
28
+ res["Content-Length"].should_not be_nil
29
+
30
+ res.body.should include('foo: bar')
31
+ end
32
+
33
+ it "should serve static files" do
34
+ res = @request.get("/index.html", :lint => true)
35
+
36
+ res.should be_ok
37
+ res["Content-Type"].should include("text/html")
38
+ end
39
+
40
+ it "should serve root with index.html if present" do
41
+ res = @request.get("/", :lint => true)
42
+
43
+ res.should be_ok
44
+ res["Content-Length"].to_i.should == File.size(@rails_app_path + '/public/index.html')
45
+ end
46
+
47
+ it "should serve page cache if present" do
48
+ res = @request.get("/simple/cached?value=cached", :lint => true)
49
+
50
+ res.should be_ok
51
+ res.body.should == 'cached'
52
+
53
+ res = @request.get("/simple/cached?value=notcached")
54
+
55
+ res.should be_ok
56
+ res.body.should == 'cached'
57
+ end
58
+
59
+ it "should not serve page cache on POST request" do
60
+ res = @request.get("/simple/cached?value=cached", :lint => true)
61
+
62
+ res.should be_ok
63
+ res.body.should == 'cached'
64
+
65
+ res = @request.post("/simple/cached?value=notcached")
66
+
67
+ res.should be_ok
68
+ res.body.should == 'notcached'
69
+ end
70
+
71
+ it "handles multiple cookies" do
72
+ res = @request.get('/simple/set_cookie?name=a&value=1', :lint => true)
73
+
74
+ res.should be_ok
75
+ res.original_headers['Set-Cookie'].size.should == 2
76
+ res.original_headers['Set-Cookie'].first.should include('a=1; path=/')
77
+ res.original_headers['Set-Cookie'].last.should include('_rails_app_session')
78
+ end
79
+
80
+ after do
81
+ FileUtils.rm_rf @rails_app_path + '/public/simple'
82
+ end
83
+ end
84
+
85
+ describe Rack::Adapter::Rails, 'with prefix' do
86
+ before do
87
+ @rails_app_path = File.dirname(__FILE__) + '/../rails_app'
88
+ @prefix = '/nowhere'
89
+ @request = Rack::MockRequest.new(
90
+ Rack::URLMap.new(
91
+ @prefix => Rack::Adapter::Rails.new(:root => @rails_app_path, :prefix => @prefix)))
92
+ end
93
+
94
+ it "should handle simple GET request" do
95
+ res = @request.get("#{@prefix}/simple", :lint => true)
96
+
97
+ res.should be_ok
98
+ res["Content-Type"].should include("text/html")
99
+
100
+ res.body.should include('Simple#index')
101
+ end
102
+ end
103
+
104
+ rescue Gem::LoadError
105
+ warn 'Rails 2.0.2 is required to run the Rails adapter specs'
106
+ end
107
+
108
+ module RailsMock
109
+ module VERSION
110
+ MAJOR = 0
111
+ MINOR = 0
112
+ TINY = 0
113
+ end
114
+ end
115
+
116
+ describe Rack::Adapter::Rails, "Adapter version" do
117
+ before do
118
+ unless defined?(::Rails)
119
+ ::Rails = RailsMock
120
+ end
121
+ end
122
+
123
+ it "should use Rack based adapter when Rails = 2.2.3" do
124
+ with_rails_version(2, 2, 3) do
125
+ Rack::Adapter::Rails.should be_rack_based
126
+ end
127
+ end
128
+
129
+ it "should not use Rack based adapter when Rails < 2.2.3" do
130
+ with_rails_version(2, 2, 2) do
131
+ Rack::Adapter::Rails.should_not be_rack_based
132
+ end
133
+ end
134
+
135
+ it "should not use Rack based adapter when Rails = 1.2.3" do
136
+ with_rails_version(1, 2, 2) do
137
+ Rack::Adapter::Rails.should_not be_rack_based
138
+ end
139
+ end
140
+
141
+ it "should use Rack based adapter when Rails = 3.0.0" do
142
+ with_rails_version(3, 0, 0) do
143
+ Rack::Adapter::Rails.should be_rack_based
144
+ end
145
+ end
146
+
147
+ def with_rails_version(major, minor, tiny)
148
+ old_major = ::Rails::VERSION::MAJOR
149
+ old_minor = ::Rails::VERSION::MINOR
150
+ old_tiny = ::Rails::VERSION::TINY
151
+
152
+ silence_warnings do
153
+ ::Rails::VERSION.const_set :MAJOR, major
154
+ ::Rails::VERSION.const_set :MINOR, minor
155
+ ::Rails::VERSION.const_set :TINY, tiny
156
+ end
157
+
158
+ yield
159
+
160
+ silence_warnings do
161
+ ::Rails::VERSION.const_set :MAJOR, old_major
162
+ ::Rails::VERSION.const_set :MINOR, old_minor
163
+ ::Rails::VERSION.const_set :TINY, old_tiny
164
+ end
165
+ end
166
+
167
+ def silence_warnings
168
+ old_verbose, $VERBOSE = $VERBOSE, nil
169
+ yield
170
+ ensure
171
+ $VERBOSE = old_verbose
172
+ end unless method_defined?(:silence_warnings)
173
+ end
@@ -0,0 +1,10 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+
7
+ # See ActionController::RequestForgeryProtection for details
8
+ # Uncomment the :secret if you're not using the cookie session store
9
+ # protect_from_forgery # :secret => 'a8af303b8dabf2d2d8f1a7912ac04d7d'
10
+ end
@@ -0,0 +1,19 @@
1
+ class SimpleController < ApplicationController
2
+ caches_page :cached
3
+
4
+ def index
5
+ end
6
+
7
+ def post_form
8
+ render :text => params.to_yaml
9
+ end
10
+
11
+ def set_cookie
12
+ cookies[params[:name]] = params[:value] if params[:name]
13
+ render :text => cookies.to_yaml
14
+ end
15
+
16
+ def cached
17
+ render :text => params[:value]
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,15 @@
1
+ <h1>Simple#index</h1>
2
+
3
+ <h2>ENV</h2>
4
+ <%= request.env.to_yaml %>
5
+
6
+ <h2>Cookies</h2>
7
+ <%= request.cookies.to_yaml %>
8
+
9
+ <h2>Params</h2>
10
+ <%= params.to_yaml %>
11
+
12
+ <% form_tag '/simple' do %>
13
+ <%= text_field_tag :a %>
14
+ <%= submit_tag 'Submit' %>
15
+ <% end %>
@@ -0,0 +1,109 @@
1
+ # Don't change this file!
2
+ # Configure your app in config/environment.rb and config/environments/*.rb
3
+
4
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
+
6
+ module Rails
7
+ class << self
8
+ def boot!
9
+ unless booted?
10
+ preinitialize
11
+ pick_boot.run
12
+ end
13
+ end
14
+
15
+ def booted?
16
+ defined? Rails::Initializer
17
+ end
18
+
19
+ def pick_boot
20
+ (vendor_rails? ? VendorBoot : GemBoot).new
21
+ end
22
+
23
+ def vendor_rails?
24
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
25
+ end
26
+
27
+ # FIXME : Ruby 1.9
28
+ def preinitialize
29
+ load(preinitializer_path) if File.exists?(preinitializer_path)
30
+ end
31
+
32
+ def preinitializer_path
33
+ "#{RAILS_ROOT}/config/preinitializer.rb"
34
+ end
35
+ end
36
+
37
+ class Boot
38
+ def run
39
+ load_initializer
40
+ Rails::Initializer.run(:set_load_path)
41
+ end
42
+ end
43
+
44
+ class VendorBoot < Boot
45
+ def load_initializer
46
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
47
+ end
48
+ end
49
+
50
+ class GemBoot < Boot
51
+ def load_initializer
52
+ self.class.load_rubygems
53
+ load_rails_gem
54
+ require 'initializer'
55
+ end
56
+
57
+ def load_rails_gem
58
+ if version = self.class.gem_version
59
+ gem 'rails', version
60
+ else
61
+ gem 'rails'
62
+ end
63
+ rescue Gem::LoadError => load_error
64
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
65
+ exit 1
66
+ end
67
+
68
+ class << self
69
+ def rubygems_version
70
+ Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
71
+ end
72
+
73
+ def gem_version
74
+ if defined? RAILS_GEM_VERSION
75
+ RAILS_GEM_VERSION
76
+ elsif ENV.include?('RAILS_GEM_VERSION')
77
+ ENV['RAILS_GEM_VERSION']
78
+ else
79
+ parse_gem_version(read_environment_rb)
80
+ end
81
+ end
82
+
83
+ def load_rubygems
84
+ require 'rubygems'
85
+
86
+ unless rubygems_version >= '0.9.4'
87
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
88
+ exit 1
89
+ end
90
+
91
+ rescue LoadError
92
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
93
+ exit 1
94
+ end
95
+
96
+ def parse_gem_version(text)
97
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
98
+ end
99
+
100
+ private
101
+ def read_environment_rb
102
+ File.read("#{RAILS_ROOT}/config/environment.rb")
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ # All that for this:
109
+ Rails.boot!