rubycas-client 2.2.1 → 2.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/Gemfile +13 -0
  2. data/Gemfile.lock +30 -0
  3. data/History.txt +21 -0
  4. data/README.rdoc +24 -20
  5. data/Rakefile +43 -54
  6. data/VERSION +1 -0
  7. data/examples/rails/README +16 -0
  8. data/examples/rails/app/controllers/advanced_example_controller.rb +31 -0
  9. data/examples/rails/app/controllers/application.rb +2 -0
  10. data/examples/rails/app/controllers/simple_example_controller.rb +16 -0
  11. data/examples/rails/app/views/advanced_example/index.html.erb +13 -0
  12. data/examples/rails/app/views/advanced_example/my_account.html.erb +11 -0
  13. data/examples/rails/app/views/simple_example/index.html.erb +6 -0
  14. data/examples/rails/config/boot.rb +109 -0
  15. data/examples/rails/config/environment.rb +39 -0
  16. data/examples/rails/config/environments/development.rb +17 -0
  17. data/examples/rails/config/environments/production.rb +22 -0
  18. data/examples/rails/config/environments/test.rb +22 -0
  19. data/examples/rails/config/initializers/inflections.rb +10 -0
  20. data/examples/rails/config/initializers/mime_types.rb +5 -0
  21. data/examples/rails/config/initializers/new_rails_defaults.rb +17 -0
  22. data/examples/rails/config/routes.rb +4 -0
  23. data/examples/rails/log/development.log +946 -0
  24. data/examples/rails/log/production.log +0 -0
  25. data/examples/rails/log/server.log +0 -0
  26. data/examples/rails/log/test.log +0 -0
  27. data/examples/rails/script/about +4 -0
  28. data/examples/rails/script/console +3 -0
  29. data/examples/rails/script/server +3 -0
  30. data/lib/casclient/client.rb +49 -36
  31. data/lib/casclient/frameworks/rails/cas_proxy_callback_controller.rb +5 -39
  32. data/lib/casclient/frameworks/rails/filter.rb +86 -113
  33. data/lib/casclient/responses.rb +29 -16
  34. data/lib/casclient/tickets/storage/active_record_ticket_store.rb +67 -0
  35. data/lib/casclient/tickets/storage.rb +167 -0
  36. data/lib/casclient/tickets.rb +3 -3
  37. data/lib/casclient.rb +3 -2
  38. data/lib/rubycas-client.rb +1 -5
  39. data/rails_generators/active_record_ticket_store/USAGE +9 -0
  40. data/rails_generators/active_record_ticket_store/active_record_ticket_store_generator.rb +29 -0
  41. data/rails_generators/active_record_ticket_store/templates/README +1 -0
  42. data/rails_generators/active_record_ticket_store/templates/migration.rb +24 -0
  43. data/rubycas-client.gemspec +103 -0
  44. data/test/teststrap.rb +10 -0
  45. data/test/units/casclient/frameworks/rails/filter_test.rb +184 -0
  46. metadata +148 -47
  47. data/Manifest.txt +0 -23
  48. data/examples/merb/README.textile +0 -12
  49. data/examples/merb/Rakefile +0 -35
  50. data/examples/merb/merb.thor +0 -2020
  51. data/examples/merb/merb_auth_cas.rb +0 -67
  52. data/examples/merb/spec/spec_helper.rb +0 -24
  53. data/init.rb +0 -6
  54. data/lib/casclient/frameworks/merb/filter.rb +0 -105
  55. data/lib/casclient/frameworks/merb/strategy.rb +0 -110
  56. data/lib/casclient/version.rb +0 -9
  57. data/setup.rb +0 -1585
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "riot"
5
+ gem "rr"
6
+ gem "bundler", "~> 1.0.0"
7
+ gem "jeweler", "~> 1.6.2"
8
+ gem "rcov"
9
+ gem "actionpack"
10
+ end
11
+
12
+ gem "activesupport"
13
+
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionpack (2.3.11)
5
+ activesupport (= 2.3.11)
6
+ rack (~> 1.1.0)
7
+ activesupport (2.3.11)
8
+ git (1.2.5)
9
+ jeweler (1.6.2)
10
+ bundler (~> 1.0)
11
+ git (>= 1.2.5)
12
+ rake
13
+ rack (1.1.2)
14
+ rake (0.9.2)
15
+ rcov (0.9.9)
16
+ riot (0.12.5)
17
+ rr
18
+ rr (1.0.4)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ actionpack
25
+ activesupport
26
+ bundler (~> 1.0.0)
27
+ jeweler (~> 1.6.2)
28
+ rcov
29
+ riot
30
+ rr
data/History.txt CHANGED
@@ -1,5 +1,26 @@
1
1
  = RubyCAS-Client Changelog
2
2
 
3
+ == Version 2.3.0 :: Prerelease
4
+
5
+ * New Functionality
6
+ * Add configuration option to expect complex extra attributes to be encoded
7
+ in json instead of yaml
8
+ * Split out storage mechanism for single sign out and proxy ticket storage so
9
+ that it is modular
10
+
11
+ * Changes to existing functionality
12
+ * Change gem building from hoe to jeweler
13
+ * expect extra attributes to be nested under a cas:attributes elemenet to
14
+ improve compatibility with other extra attribute implementations
15
+ * Unauthorized requests to URLs ending in .json now show an JSON formatted
16
+ response
17
+
18
+ * Bug Fixes
19
+ * Fixed bug introduced by upstream patch that broke proxy ticket validation
20
+ when using extra attributes
21
+ * Fixed bug where extra attributes key was set on the session with a null
22
+ value when faking with no extra attributes
23
+
3
24
  == Version 2.2.1 :: 2010-06-24
4
25
 
5
26
  * Removed a 3rd party patch to the logging mechanism that broke the client under
data/README.rdoc CHANGED
@@ -1,13 +1,13 @@
1
1
  = RubyCAS-Client
2
2
 
3
- Author:: Matt Zukowski <matt AT roughest DOT net>; inspired by code by Ola Bini <ola.bini AT ki DOT se> and Matt Walker <mwalker AT tamu DOT edu>
3
+ Authors:: Matt Zukowski <matt AT roughest DOT net> and Matt Campbell <matt AT soupmatt DOT com>; inspired by code by Ola Bini <ola.bini AT ki DOT se> and Matt Walker <mwalker AT tamu DOT edu>
4
4
  Copyright:: Portions contributed by Matt Zukowski are copyright (c) 2009 Urbacon Ltd.
5
+ Portions contributed by Matt Campbell, Rich Yarger and Rahul Joshi are copyright (c) 2011 Vibes Media LLC.
5
6
  Other portions are copyright of their respective authors.
6
7
  License:: MIT License
7
- Websites:: http://github.com/gunark/rubycas-client
8
- http://code.google.com/p/rubycas-client
9
- http://rubyforge.org/projects/rubycas-client
10
-
8
+ Websites:: http://github.com/rubycas/rubycas-client
9
+ http://github.com/rubycas/rubycas-client/wiki
10
+ http://rubydoc.info/github/rubycas/rubycas-client/master/frames
11
11
 
12
12
 
13
13
  === RubyCAS-Client is a Ruby client library for Yale's Central Authentication Service (CAS) protocol.
@@ -36,13 +36,18 @@ API documentation (i.e. the RDocs) are available at http://rubycas-client.rubyfo
36
36
 
37
37
  == Installation
38
38
 
39
+ <b>NOTE:</b> For compatibility with Rails 3 have a look at https://github.com/zuk/rubycas-client-rails
40
+
41
+ The current version of RubyCAS-Client should work with Rails 2.3.6 and up. For compatibility with
42
+ older Rails try using an older version of the client.
43
+
39
44
  You can download the latest version of RubyCAS-Client from the project's rubyforge page at
40
45
  http://rubyforge.org/projects/rubycas-client.
41
46
 
42
47
  However, if you're using Rails, it's easier to install the CAS client as a plugin:
43
48
 
44
49
  cd <your rails app>
45
- ./script/plugin install http://rubycas-client.googlecode.com/svn/trunk/rubycas-client
50
+ ./script/plugin install git://github.com/gunark/rubycas-client.git
46
51
 
47
52
  Alternatively, the library is also installable as a RubyGem[http://rubygems.org]:
48
53
 
@@ -51,11 +56,8 @@ Alternatively, the library is also installable as a RubyGem[http://rubygems.org]
51
56
  If your Rails application is under Subversion control, you can also install the plugin as an svn:external, ensuring that
52
57
  you always have the latest bleeding-edge version of RubyCAS-Client:
53
58
 
54
- ./script/plugin install -x http://rubycas-client.googlecode.com/svn/trunk/rubycas-client
59
+ ./script/plugin install -x http://svn.github.com/gunark/rubycas-client.git
55
60
 
56
- With Rails 2.1 or newer, it is also possible to install the plugin directly from the bleeding-edge git repository:
57
-
58
- ./script/plugin install git://github.com/gunark/rubycas-client.git
59
61
 
60
62
  == Usage Examples
61
63
 
@@ -108,7 +110,7 @@ Here is a more complicated configuration showing most of the configuration optio
108
110
  (this does not show proxy options, which are covered in the next section):
109
111
 
110
112
  # enable detailed CAS logging
111
- cas_logger = CASClient::Logger.new(RAILS_ROOT+'/log/cas.log')
113
+ cas_logger = CASClient::Logger.new(::Rails.root+'/log/cas.log')
112
114
  cas_logger.level = Logger::DEBUG
113
115
 
114
116
  CASClient::Frameworks::Rails::Filter.configure(
@@ -149,7 +151,7 @@ notify the client application that the CAS session is closed. The client will au
149
151
  requsts from the CAS server, but in order for this to work you must configure your Rails application as follows:
150
152
 
151
153
  1. The Rails session store must be set to ActiveRecord: <tt>config.action_controller.session_store = :active_record_store</tt>
152
- 2. The server must be able to read and write to RAILS_ROOT/tmp/sessions. If you are in a clustered environment,
154
+ 2. The server must be able to read and write to Rails.root/tmp/sessions. If you are in a clustered environment,
153
155
  the contents of this directory must be shared between all server instances.
154
156
  3. Cross-site request forgery protection must be disabled. In your <tt>application.rb</tt>: <tt>self.allow_forgery_protection = false</tt>.
155
157
  (Or rather you may want to disable forgery protection only for actions that are behind the CAS filter.)
@@ -230,12 +232,11 @@ all you need to do is this:
230
232
  In your <tt>config/environment.rb</tt>:
231
233
 
232
234
  # enable detailed CAS logging for easier troubleshooting
233
- cas_logger = CASClient::Logger.new(RAILS_ROOT+'/log/cas.log')
235
+ cas_logger = CASClient::Logger.new(::Rails.root+'/log/cas.log')
234
236
  cas_logger.level = Logger::DEBUG
235
237
 
236
238
  CASClient::Frameworks::Rails::Filter.configure(
237
239
  :cas_base_url => "https://cas.example.foo/",
238
- :proxy_retrieval_url => "https://cas-proxy-callback.example.foo/cas_proxy_callback/retrieve_pgt",
239
240
  :proxy_callback_url => "https://cas-proxy-callback.example.foo/cas_proxy_callback/receive_pgt",
240
241
  :logger => cas_logger
241
242
  )
@@ -255,12 +256,9 @@ but your Rails server wouldn't respond to the CAS server's callback until the CA
255
256
 
256
257
  The simplest workaround is this:
257
258
 
258
- 1. Create an empty rails app (i.e. something like <tt>rails cas_proxy_callback</tt>)
259
- 2. Make sure that you have the CAS plugin installed. If you installed it as a gem, you don't have to do anything since
260
- it is already installed. If you want to install as a plugin, see the instructions in the "Installing" section above.
261
- 3. Make sure that the server is up and running, and configure your proxy_callback_url and proxy_retrieval_url to point
262
- to the new server as described above (or rather, make Pound point to the new server, if that's how you're handling https).
263
-
259
+ Run rails using a server that handles multiple concurrent requests. In development, you can use Phusion Passenger Standalone,
260
+ POW (http://pow.cx/), unicorn and many others. In production, I imagine you already support multiple concurrent requests.
261
+
264
262
  That's it. The proxy_callback_controller doesn't require any additional configuration. It doesn't access the database
265
263
  or anything of that sort.
266
264
 
@@ -316,6 +314,12 @@ In your test or Cucumber step definition, simply fake out CAS.
316
314
  This functionality was present in the original version of this plugin.
317
315
  The value of the username is stored in session[:cas_user] (or the user specified field) and session[:casfilteruser] for backwards-compatibility.
318
316
 
317
+ If you need to fake out extra attributes, you can do so like this:
318
+
319
+ CASClient::Frameworks::Rails::Filter.fake("homer", {:role => "user", :email => "homer@test.foo"})
320
+
321
+ And the extra attributes will get put in the proper place in the session.
322
+
319
323
  == License
320
324
 
321
325
  RubyCAS-Client is licensed for use under the terms of the MIT License.
data/Rakefile CHANGED
@@ -1,63 +1,52 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
2
12
  require 'rake'
3
- require 'rake/clean'
4
- require 'rake/testtask'
5
- require 'rake/packagetask'
6
- require 'rake/gempackagetask'
7
- require 'rake/rdoctask'
8
- require 'rake/contrib/rubyforgepublisher'
9
- require 'fileutils'
10
- require 'hoe'
11
- include FileUtils
12
- require File.join(File.dirname(__FILE__), 'lib', 'casclient', 'version')
13
-
14
- AUTHOR = ["Matt Zukowski", "Matt Walker"] # can also be an array of Authors
15
- EMAIL = "matt at roughest dot net"
16
- DESCRIPTION = "Client library for the Central Authentication Service (CAS) protocol."
17
- GEM_NAME = "rubycas-client" # what ppl will type to install your gem
18
- RUBYFORGE_PROJECT = "rubycas-client" # The unix name for your project
19
- HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
20
-
21
- ENV['NODOT'] = '1'
22
13
 
23
- NAME = "rubycas-client"
24
- REV = nil
25
- #REV = `svn info`[/Revision: (\d+)/, 1] rescue nil
26
- VERS = ENV['VERSION'] || (CASClient::VERSION::STRING + (REV ? ".#{REV}" : ""))
27
- CLEAN.include ['**/.*.sw?', '*.gem', '.config']
28
- RDOC_OPTS = ['--quiet', '--title', "rubycas-client documentation",
29
- "--opname", "index.html",
30
- "--line-numbers",
31
- "--main", "README",
32
- "--inline-source"]
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ gem.name = "rubycas-client"
17
+ gem.homepage = "http://github.com/rubycas/rubycas-client"
18
+ gem.license = "MIT"
19
+ gem.summary = "Client library for the Central Authentication Service (CAS) protocol."
20
+ gem.authors = ["Matt Zukowski", "Matt Walker", "Matt Campbell"]
21
+ gem.rdoc_options = ['--main', 'README.rdoc']
22
+ gem.files.exclude '.rvmrc', '.infinity_test'
23
+ # dependencies defined in Gemfile
24
+ end
25
+ Jeweler::RubygemsDotOrgTasks.new
33
26
 
34
- class Hoe
35
- def extra_deps
36
- @extra_deps.reject { |x| Array(x).first == 'hoe' }
37
- end
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
38
32
  end
39
33
 
40
- # Generate all the Rake tasks
41
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
42
- hoe = Hoe.new(GEM_NAME, VERS) do |p|
43
- p.author = AUTHOR
44
- p.description = DESCRIPTION
45
- p.email = EMAIL
46
- p.summary = DESCRIPTION
47
- p.url = HOMEPATH
48
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
49
- p.test_globs = ["test/**/*_test.rb"]
50
- p.clean_globs = CLEAN #An array of file patterns to delete on clean.
51
-
52
- # == Optional
53
- #p.changes - A description of the release's latest changes.
54
- #p.extra_deps - An array of rubygem dependencies.
55
- #p.spec_extras - A hash of extra values to set in the gemspec.
56
- p.extra_deps = ['activesupport']
34
+ require 'rcov/rcovtask'
35
+ Rcov::RcovTask.new do |test|
36
+ test.libs << 'test'
37
+ test.pattern = 'test/**/test_*.rb'
38
+ test.verbose = true
39
+ test.rcov_opts << '--exclude "gems/*"'
57
40
  end
58
41
 
59
- desc 'Build and install rubycas-client'
60
- task :install do
61
- system "gem build rubycas-client.gemspec"
62
- system "sudo gem install rubycas-client-#{VERS}.gem"
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "rubycas-client #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
63
52
  end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.3.0.rc1
@@ -0,0 +1,16 @@
1
+ This is a skeleton Rails application hooked up for CAS authentication.
2
+
3
+ To try this out:
4
+
5
+ 1. If you have an existing CAS server, modify the CAS client settings in
6
+ config/environment.rb to point to your server. If you do not yet
7
+ have a CAS server, install rubycas-server, and configure it to run on
8
+ http://localhost:7777 (or modify environment.rb to your likings).
9
+
10
+ 2. Run `ruby script/server`
11
+
12
+ 3. Point your web browser to http://localhost:3000
13
+
14
+ 4. Have a look at the source code in app/controllers/simple_example_controller.rb
15
+ and app/controllers/advanced_example_controller.rb. The
16
+ corresponding views under app/views might also be worth looking at.
@@ -0,0 +1,31 @@
1
+ # A more advanced example.
2
+ # For basic usage see the SimpleExampleController.
3
+ class AdvancedExampleController < ApplicationController
4
+ # This will allow the user to view the index page without authentication
5
+ # but will process CAS authentication data if the user already
6
+ # has an SSO session open.
7
+ before_filter CASClient::Frameworks::Rails::GatewayFilter, :only => :index
8
+
9
+ # This requires the user to be authenticated for viewing allother pages.
10
+ before_filter CASClient::Frameworks::Rails::Filter, :except => :index
11
+
12
+ def index
13
+ @username = session[:cas_user]
14
+
15
+ @login_url = CASClient::Frameworks::Rails::Filter.login_url(self)
16
+ end
17
+
18
+ def my_account
19
+ @username = session[:cas_user]
20
+
21
+ # Additional user attributes are available if your
22
+ # CAS server is configured to provide them.
23
+ # See http://code.google.com/p/rubycas-server/wiki/HowToSendExtraUserAttributes
24
+ @extra_attributes = session[:cas_extra_attributes]
25
+ end
26
+
27
+ def logout
28
+ CASClient::Frameworks::Rails::Filter.logout(self)
29
+ end
30
+
31
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,16 @@
1
+ # This is the most basic, bare-bones example.
2
+ # For advanced usage see the AdvancedExampleController.
3
+ class SimpleExampleController < ApplicationController
4
+ # This will force CAS authentication before the user
5
+ # is allowed to access any action in this controller.
6
+ before_filter CASClient::Frameworks::Rails::Filter
7
+
8
+ def index
9
+ @username = session[:cas_user]
10
+ end
11
+
12
+ def logout
13
+ CASClient::Frameworks::Rails::Filter.logout(self)
14
+ end
15
+
16
+ end
@@ -0,0 +1,13 @@
1
+ <h1>AdvancedExample#index</h1>
2
+
3
+ <% if @username %>
4
+ <p>Hello, <%= @username %>! You are authenticated.</p>
5
+ <% else %>
6
+ <p>You are not yet authenticated. <%= link_to("Login", @login_url) %>
7
+ <% end %>
8
+
9
+ <p>&raquo; <%= link_to("Go To My Account", :action => 'my_account') %></p>
10
+
11
+ <% if @username %>
12
+ <p>[ <%= link_to("Logout", :action => 'logout') %> ]</p>
13
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <h1>AdvancedExample#my_account</h1>
2
+ <p><%= @username %>'s Account page</p>
3
+
4
+ <p>
5
+ <strong>Extra Attributes</strong>:<br />
6
+ <% unless @extra_attributes.blank? %>
7
+ <%= debug(@extra_attributes) %>
8
+ <% end %>
9
+ </p>
10
+
11
+ <p>[ <%= link_to("Logout", :action => 'logout') %> ]</p>
@@ -0,0 +1,6 @@
1
+ <h1>SimpleExample#index</h1>
2
+ <p>Hello, <%= @username %>!</p>
3
+
4
+ <p>&raquo; <%= link_to("Go To AdvancedExample", :controller => 'advanced_example') %></p>
5
+
6
+ <p>[ <%= link_to("Logout", :action => 'logout') %> ]</p>
@@ -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
+ def preinitialize
28
+ load(preinitializer_path) if File.exist?(preinitializer_path)
29
+ end
30
+
31
+ def preinitializer_path
32
+ "#{Rails.root}/config/preinitializer.rb"
33
+ end
34
+ end
35
+
36
+ class Boot
37
+ def run
38
+ load_initializer
39
+ Rails::Initializer.run(:set_load_path)
40
+ end
41
+ end
42
+
43
+ class VendorBoot < Boot
44
+ def load_initializer
45
+ require "#{Rails.root}/vendor/rails/railties/lib/initializer"
46
+ Rails::Initializer.run(:install_gem_spec_stubs)
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
+ min_version = '1.1.1'
86
+ unless rubygems_version >= min_version
87
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
88
+ exit 1
89
+ end
90
+
91
+ rescue LoadError
92
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. 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!