nxa-sunspot_rails 0.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/History.txt +15 -0
  2. data/LICENSE +18 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +260 -0
  5. data/Rakefile +27 -0
  6. data/TODO +8 -0
  7. data/VERSION.yml +4 -0
  8. data/dev_tasks/gemspec.rake +55 -0
  9. data/dev_tasks/rdoc.rake +7 -0
  10. data/dev_tasks/release.rake +4 -0
  11. data/dev_tasks/todo.rake +4 -0
  12. data/generators/sunspot/sunspot_generator.rb +9 -0
  13. data/generators/sunspot/templates/sunspot.yml +18 -0
  14. data/install.rb +1 -0
  15. data/lib/sunspot/rails/adapters.rb +79 -0
  16. data/lib/sunspot/rails/configuration.rb +248 -0
  17. data/lib/sunspot/rails/request_lifecycle.rb +22 -0
  18. data/lib/sunspot/rails/searchable.rb +309 -0
  19. data/lib/sunspot/rails/server.rb +229 -0
  20. data/lib/sunspot/rails/session_proxy.rb +62 -0
  21. data/lib/sunspot/rails/tasks.rb +35 -0
  22. data/lib/sunspot/rails/util.rb +20 -0
  23. data/lib/sunspot/rails.rb +22 -0
  24. data/lib/sunspot/spec/extension.rb +45 -0
  25. data/rails/init.rb +7 -0
  26. data/spec/configuration_spec.rb +102 -0
  27. data/spec/mock_app/app/controllers/application.rb +10 -0
  28. data/spec/mock_app/app/controllers/application_controller.rb +10 -0
  29. data/spec/mock_app/app/controllers/posts_controller.rb +6 -0
  30. data/spec/mock_app/app/models/author.rb +8 -0
  31. data/spec/mock_app/app/models/blog.rb +2 -0
  32. data/spec/mock_app/app/models/post.rb +5 -0
  33. data/spec/mock_app/app/models/post_with_auto.rb +9 -0
  34. data/spec/mock_app/config/boot.rb +110 -0
  35. data/spec/mock_app/config/database.yml +4 -0
  36. data/spec/mock_app/config/environment.rb +42 -0
  37. data/spec/mock_app/config/environments/development.rb +27 -0
  38. data/spec/mock_app/config/environments/test.rb +27 -0
  39. data/spec/mock_app/config/initializers/new_rails_defaults.rb +19 -0
  40. data/spec/mock_app/config/initializers/session_store.rb +15 -0
  41. data/spec/mock_app/config/routes.rb +43 -0
  42. data/spec/mock_app/config/sunspot.yml +19 -0
  43. data/spec/mock_app/db/schema.rb +20 -0
  44. data/spec/model_lifecycle_spec.rb +53 -0
  45. data/spec/model_spec.rb +314 -0
  46. data/spec/request_lifecycle_spec.rb +52 -0
  47. data/spec/schema.rb +20 -0
  48. data/spec/server_spec.rb +124 -0
  49. data/spec/session_spec.rb +24 -0
  50. data/spec/spec_helper.rb +51 -0
  51. data/spec/sunspot_mocking_spec.rb +22 -0
  52. data/spec/util_spec.rb +15 -0
  53. metadata +203 -0
@@ -0,0 +1,229 @@
1
+ require 'escape'
2
+
3
+ module Sunspot #:nodoc:
4
+ module Rails #:nodoc:
5
+ # The Sunspot::Rails::Server class is a simple wrapper around
6
+ # the start/stop scripts for solr.
7
+ class Server
8
+
9
+ class << self
10
+ delegate :log_file, :log_level, :port, :solr_home, :to => :configuration
11
+
12
+ # Name of the sunspot executable (shell script)
13
+ SUNSPOT_EXECUTABLE = (RUBY_PLATFORM =~ /w(in)?32$/ ? 'sunspot-solr.bat' : 'sunspot-solr')
14
+
15
+ #
16
+ # Start the sunspot-solr server. Bootstrap solr_home first,
17
+ # if neccessary.
18
+ #
19
+ # ==== Returns
20
+ #
21
+ # Boolean:: success
22
+ #
23
+ def start
24
+ bootstrap if bootstrap_neccessary?
25
+ execute( start_command )
26
+ end
27
+
28
+ #
29
+ # Run the sunspot-solr server in the foreground. Boostrap
30
+ # solr_home first, if neccessary.
31
+ #
32
+ # ==== Returns
33
+ #
34
+ # Boolean:: success
35
+ #
36
+ def run
37
+ bootstrap if bootstrap_neccessary?
38
+ execute( run_command )
39
+ end
40
+
41
+ #
42
+ # Stop the sunspot-solr server.
43
+ #
44
+ # ==== Returns
45
+ #
46
+ # Boolean:: success
47
+ #
48
+ def stop
49
+ execute( stop_command )
50
+ end
51
+
52
+ #
53
+ # Directory to store solr config files
54
+ #
55
+ # ==== Returns
56
+ #
57
+ # String:: config_path
58
+ #
59
+ def config_path
60
+ File.join( solr_home, 'conf' )
61
+ end
62
+
63
+ #
64
+ # Directory to store lucene index data files
65
+ #
66
+ # ==== Returns
67
+ #
68
+ # String:: data_path
69
+ #
70
+ def data_path
71
+ File.join( solr_home, 'data', ::Rails.env )
72
+ end
73
+
74
+ #
75
+ # Directory to store custom libraries for solr
76
+ #
77
+ # ==== Returns
78
+ #
79
+ # String:: lib_path
80
+ #
81
+ def lib_path
82
+ File.join( solr_home, 'lib' )
83
+ end
84
+
85
+ #
86
+ # Directory to store pid files
87
+ #
88
+ # ==== Returns
89
+ #
90
+ # String:: pid_path
91
+ #
92
+ def pid_path
93
+ File.join( solr_home, 'pids', ::Rails.env )
94
+ end
95
+
96
+ #
97
+ # Bootstrap a new solr_home by creating all required
98
+ # directories.
99
+ #
100
+ # ==== Returns
101
+ #
102
+ # Boolean:: success
103
+ #
104
+ def bootstrap
105
+ create_solr_directories and create_solr_configuration_files and copy_custom_solr_libraries
106
+ end
107
+
108
+ #
109
+ # Check for bootstrap necessity
110
+ #
111
+ # ==== Returns
112
+ #
113
+ # Boolean:: neccessary
114
+ #
115
+ def bootstrap_neccessary?
116
+ !File.directory?( solr_home ) or !File.exists?( File.join( config_path, 'solrconfig.xml' ) )
117
+ end
118
+
119
+
120
+ protected
121
+
122
+ #
123
+ # Generate the start command for the sunspot-solr executable
124
+ #
125
+ # ==== Returns
126
+ #
127
+ # Array:: sunspot_start_command
128
+ #
129
+ def start_command
130
+ [ SUNSPOT_EXECUTABLE, 'start', '-p', port.to_s, '-d', data_path, '-s', solr_home, '-l', log_level, '--log-file', log_file ]
131
+ end
132
+
133
+ #
134
+ # Generate the stop command for the sunspot-solr executable
135
+ #
136
+ # ==== Returns
137
+ #
138
+ # Array:: sunspot_stop_command
139
+ #
140
+ def stop_command
141
+ [ SUNSPOT_EXECUTABLE, 'stop' ]
142
+ end
143
+
144
+ #
145
+ # Generate the run command for the sunspot-solr executable
146
+ #
147
+ # ==== Returns
148
+ #
149
+ # Array:: run_command
150
+ #
151
+ def run_command
152
+ [ SUNSPOT_EXECUTABLE, 'run', '-p', port.to_s, '-d', data_path, '-s', solr_home, '-l', log_level, '-lf', log_file ]
153
+ end
154
+
155
+ #
156
+ # access to the Sunspot::Rails::Configuration, defined in
157
+ # sunspot.yml. Use Sunspot::Rails.configuration if you want
158
+ # to access the configuration directly.
159
+ #
160
+ # ==== returns
161
+ #
162
+ # Sunspot::Rails::Configuration:: configuration
163
+ #
164
+ def configuration
165
+ Sunspot::Rails.configuration
166
+ end
167
+
168
+ private
169
+
170
+ #
171
+ # Change directory to the pid file path and execute a
172
+ # command on a subshell.
173
+ #
174
+ # ==== Returns
175
+ #
176
+ # Boolean:: success
177
+ #
178
+ def execute( command )
179
+ success = false
180
+ FileUtils.cd( pid_path ) do
181
+ success = Kernel.system(Escape.shell_command( command ))
182
+ end
183
+ success
184
+ end
185
+
186
+ #
187
+ # Create new solr_home, config, log and pid directories
188
+ #
189
+ # ==== Returns
190
+ #
191
+ # Boolean:: success
192
+ #
193
+ def create_solr_directories
194
+ [ solr_home, config_path, data_path, pid_path, lib_path ].each do |path|
195
+ FileUtils.mkdir_p( path )
196
+ end
197
+ end
198
+
199
+ #
200
+ # Copy custom solr libraries (like localsolr) to the
201
+ # lib directory
202
+ #
203
+ # ==== Returns
204
+ #
205
+ # Boolean:: success
206
+ #
207
+ def copy_custom_solr_libraries
208
+ Dir.glob( File.join( Sunspot::Configuration.solr_default_configuration_location, '..', 'lib', '*.jar') ).each do |jar_file|
209
+ FileUtils.cp( jar_file, lib_path )
210
+ end
211
+ end
212
+
213
+ #
214
+ # Copy default solr configuration files from sunspot
215
+ # gem to the new solr_home/config directory
216
+ #
217
+ # ==== Returns
218
+ #
219
+ # Boolean:: success
220
+ #
221
+ def create_solr_configuration_files
222
+ Dir.glob( File.join( Sunspot::Configuration.solr_default_configuration_location, '*') ).each do |config_file|
223
+ FileUtils.cp( config_file, config_path )
224
+ end
225
+ end
226
+ end
227
+ end
228
+ end
229
+ end
@@ -0,0 +1,62 @@
1
+ module Sunspot
2
+ module Rails
3
+ class SessionProxy
4
+ extend MonitorMixin
5
+
6
+ class <<self
7
+ def instance
8
+ synchronize do
9
+ @instance ||= new
10
+ end
11
+ end
12
+
13
+ def reset!
14
+ synchronize do
15
+ @instance = nil
16
+ end
17
+ end
18
+
19
+ private :new
20
+ end
21
+
22
+ delegate :new_search, :search, :to => :read_session
23
+ delegate :index, :index!, :commit, :remove, :remove!, :remove_by_id,
24
+ :remove_by_id!, :remove_all, :remove_all!, :dirty?, :commit_if_dirty, :batch,
25
+ :to => :write_session
26
+
27
+ def initialize
28
+ @configuration = Sunspot::Rails::Configuration.new
29
+ end
30
+
31
+ private
32
+
33
+ def read_session
34
+ Thread.current[:sunspot_rails_read_session] ||=
35
+ begin
36
+ session = Sunspot::Session.new
37
+ session.config.solr.url = URI::HTTP.build(
38
+ :host => @configuration.hostname,
39
+ :port => @configuration.port,
40
+ :path => @configuration.path
41
+ ).to_s
42
+ session
43
+ end
44
+ end
45
+
46
+ def write_session
47
+ Thread.current[:sunspot_rails_write_session] ||=
48
+ if @configuration.has_master?
49
+ master_session = Sunspot::Session.new
50
+ master_session.config.solr.url = URI::HTTP.build(
51
+ :host => configuration.master_hostname,
52
+ :port => configuration.master_port,
53
+ :path => configuration.master_path
54
+ ).to_s
55
+ master_session
56
+ else
57
+ read_session
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,35 @@
1
+ namespace :sunspot do
2
+ namespace :solr do
3
+ desc 'Start the Solr instance'
4
+ task :start => :environment do
5
+ if RUBY_PLATFORM =~ /w(in)?32$/
6
+ abort('This command does not work on Windows. Please use rake sunspot:solr:run to run Solr in the foreground.')
7
+ end
8
+ Sunspot::Rails::Server.start
9
+ end
10
+
11
+ desc 'Run the Solr instance in the foreground'
12
+ task :run => :environment do
13
+ Sunspot::Rails::Server.run
14
+ end
15
+
16
+ desc 'Stop the Solr instance'
17
+ task :stop => :environment do
18
+ if RUBY_PLATFORM =~ /w(in)?32$/
19
+ abort('This command does not work on Windows.')
20
+ end
21
+ Sunspot::Rails::Server.stop
22
+ end
23
+
24
+ desc 'Reindex all solr models'
25
+ task :reindex => :environment do
26
+ all_files = Dir.glob(File.join(RAILS_ROOT, 'app', 'models', '*.rb'))
27
+ all_models = all_files.map { |path| File.basename(path, '.rb').camelize.constantize }
28
+ sunspot_models = all_models.select { |m| m < ActiveRecord::Base and m.searchable? }
29
+
30
+ sunspot_models.each do |model|
31
+ model.reindex :batch_commit => false
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,20 @@
1
+ require 'escape'
2
+
3
+ module Sunspot #:nodoc:
4
+ module Rails #:nodoc:
5
+ class Util
6
+ class << self
7
+ def sunspot_options
8
+ @sunspot_options ||= {}
9
+ end
10
+
11
+ def index_relevant_attribute_changed?( object )
12
+ class_key = object.class.to_s.underscore.to_sym
13
+ ignore_attributes = (sunspot_options[class_key][:ignore_attribute_changes_of] || [])
14
+ !(object.changes.symbolize_keys.keys - ignore_attributes).blank?
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ require 'sunspot'
2
+ require 'sunspot/rails/configuration'
3
+ require 'sunspot/rails/adapters'
4
+ require 'sunspot/rails/request_lifecycle'
5
+ require 'sunspot/rails/searchable'
6
+ require 'sunspot/rails/util'
7
+
8
+ module Sunspot #:nodoc:
9
+ module Rails #:nodoc:
10
+ class <<self
11
+ attr_writer :configuration
12
+
13
+ def configuration
14
+ @configuration ||= Sunspot::Rails::Configuration.new
15
+ end
16
+
17
+ def reset
18
+ @master_session = @configuration = nil
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,45 @@
1
+ module Sunspot
2
+ module Rails
3
+ module Spec
4
+ module Extension
5
+ def self.included(base)
6
+ base.class_eval do
7
+ class_inheritable_accessor :sunspot_integration
8
+ extend ClassMethods
9
+ end
10
+ end
11
+
12
+ def integrate_sunspot?
13
+ self.class.integrate_sunspot?
14
+ end
15
+
16
+ def mock_sunspot
17
+ [ :index, :remove_from_index ].each do |method_name|
18
+ Sunspot.stub!(method_name)
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ module ClassMethods
25
+ def integrate_sunspot( integrate = true )
26
+ self.sunspot_integration = integrate
27
+ end
28
+
29
+ def integrate_sunspot?
30
+ !!self.sunspot_integration
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ module ActiveSupport
38
+ class TestCase
39
+ before(:each) do
40
+ mock_sunspot unless integrate_sunspot?
41
+ end
42
+
43
+ include Sunspot::Rails::Spec::Extension
44
+ end
45
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'sunspot'
2
+
3
+ Sunspot.session = Sunspot::Rails::SessionProxy.instance
4
+ Sunspot::Adapters::InstanceAdapter.register(Sunspot::Rails::Adapters::ActiveRecordInstanceAdapter, ActiveRecord::Base)
5
+ Sunspot::Adapters::DataAccessor.register(Sunspot::Rails::Adapters::ActiveRecordDataAccessor, ActiveRecord::Base)
6
+ ActiveRecord::Base.module_eval { include(Sunspot::Rails::Searchable) }
7
+ ActionController::Base.module_eval { include(Sunspot::Rails::RequestLifecycle) }
@@ -0,0 +1,102 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Sunspot::Rails::Configuration, "default values" do
4
+ before(:each) do
5
+ File.should_receive(:exist?).at_least(:once).and_return(false)
6
+ @config = Sunspot::Rails::Configuration.new
7
+ end
8
+
9
+ it "should handle the 'hostname' property when not set" do
10
+ @config.hostname.should == 'localhost'
11
+ end
12
+
13
+ it "should handle the 'path' property when not set" do
14
+ @config.path.should == '/solr'
15
+ end
16
+
17
+ it "should handle the 'port' property when not set" do
18
+ @config.port.should == 8983
19
+ end
20
+
21
+ it "should handle the 'log_level' property when not set" do
22
+ @config.log_level.should == 'INFO'
23
+ end
24
+
25
+ it "should handle the 'log_file' property" do
26
+ @config.log_file.should =~ /log\/solr_test.log/
27
+ end
28
+
29
+ it "should handle the 'solr_home' property when not set" do
30
+ Rails.should_receive(:root).at_least(1).and_return('/some/path')
31
+ @config.solr_home.should == '/some/path/solr'
32
+ end
33
+
34
+ it "should handle the 'data_path' property when not set" do
35
+ Rails.should_receive(:root).at_least(1).and_return('/some/path')
36
+ @config.data_path.should == '/some/path/solr/data/test'
37
+ end
38
+
39
+ it "should handle the 'pid_path' property when not set" do
40
+ Rails.should_receive(:root).at_least(1).and_return('/some/path')
41
+ @config.pid_path.should == '/some/path/solr/pids/test'
42
+ end
43
+
44
+ it "should handle the 'solr_home' property when not set" do
45
+ @config.solr_home.should_not == nil
46
+ end
47
+
48
+ it "should handle the 'auto_commit_after_request' propery when not set" do
49
+ @config.auto_commit_after_request?.should == true
50
+ end
51
+
52
+ it "should handle the 'auto_commit_after_delete_request' propery when not set" do
53
+ @config.auto_commit_after_delete_request?.should == false
54
+ end
55
+ end
56
+
57
+ describe Sunspot::Rails::Configuration, "user settings" do
58
+ before(:each) do
59
+ ::Rails.stub!(:env => 'config_test')
60
+ @config = Sunspot::Rails::Configuration.new
61
+ end
62
+
63
+ it "should handle the 'hostname' property when set" do
64
+ @config.hostname.should == 'some.host'
65
+ end
66
+
67
+ it "should handle the 'port' property when set" do
68
+ @config.port.should == 1234
69
+ end
70
+
71
+ it "should handle the 'path' property when set" do
72
+ @config.path.should == '/solr/idx'
73
+ end
74
+
75
+ it "should handle the 'log_level' propery when set" do
76
+ @config.log_level.should == 'WARNING'
77
+ end
78
+
79
+ it "should handle the 'solr_home' propery when set" do
80
+ @config.solr_home.should == '/my_superior_path'
81
+ end
82
+
83
+ it "should handle the 'data_path' property when set" do
84
+ @config.data_path.should == '/my_superior_path/data'
85
+ end
86
+
87
+ it "should handle the 'pid_path' property when set" do
88
+ @config.pid_path.should == '/my_superior_path/pids'
89
+ end
90
+
91
+ it "should handle the 'solr_home' property when set" do
92
+ @config.solr_home.should == '/my_superior_path'
93
+ end
94
+
95
+ it "should handle the 'auto_commit_after_request' propery when set" do
96
+ @config.auto_commit_after_request?.should == false
97
+ end
98
+
99
+ it "should handle the 'auto_commit_after_delete_request' propery when set" do
100
+ @config.auto_commit_after_delete_request?.should == true
101
+ end
102
+ 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
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
7
+
8
+ # Scrub sensitive parameters from your log
9
+ # filter_parameter_logging :password
10
+ 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
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
7
+
8
+ # Scrub sensitive parameters from your log
9
+ # filter_parameter_logging :password
10
+ end
@@ -0,0 +1,6 @@
1
+ class PostsController < ApplicationController
2
+ def create
3
+ PostWithAuto.create(params[:post])
4
+ render :nothing => true
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ class Author < ActiveRecord::Base
2
+ set_table_name :writers
3
+ set_primary_key :writer_id
4
+
5
+ searchable do
6
+ string :name
7
+ end
8
+ end
@@ -0,0 +1,2 @@
1
+ class Blog < ActiveRecord::Base
2
+ end
@@ -0,0 +1,5 @@
1
+ class Post < ActiveRecord::Base
2
+ searchable :auto_index => false, :auto_remove => false do
3
+ string :title
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class PostWithAuto < ActiveRecord::Base
2
+ def self.table_name
3
+ 'posts'
4
+ end
5
+
6
+ searchable :ignore_attribute_changes_of => [ :updated_at ] do
7
+ string :title
8
+ end
9
+ end
@@ -0,0 +1,110 @@
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
+ Rails::GemDependency.add_frozen_gem_path
48
+ end
49
+ end
50
+
51
+ class GemBoot < Boot
52
+ def load_initializer
53
+ self.class.load_rubygems
54
+ load_rails_gem
55
+ require 'initializer'
56
+ end
57
+
58
+ def load_rails_gem
59
+ if version = self.class.gem_version
60
+ gem 'rails', version
61
+ else
62
+ gem 'rails'
63
+ end
64
+ rescue Gem::LoadError => load_error
65
+ $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.)
66
+ exit 1
67
+ end
68
+
69
+ class << self
70
+ def rubygems_version
71
+ Gem::RubyGemsVersion rescue nil
72
+ end
73
+
74
+ def gem_version
75
+ if defined? RAILS_GEM_VERSION
76
+ RAILS_GEM_VERSION
77
+ elsif ENV.include?('RAILS_GEM_VERSION')
78
+ ENV['RAILS_GEM_VERSION']
79
+ else
80
+ parse_gem_version(read_environment_rb)
81
+ end
82
+ end
83
+
84
+ def load_rubygems
85
+ require 'rubygems'
86
+ min_version = '1.3.1'
87
+ unless rubygems_version >= min_version
88
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
89
+ exit 1
90
+ end
91
+
92
+ rescue LoadError
93
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
94
+ exit 1
95
+ end
96
+
97
+ def parse_gem_version(text)
98
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
99
+ end
100
+
101
+ private
102
+ def read_environment_rb
103
+ File.read("#{RAILS_ROOT}/config/environment.rb")
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ # All that for this:
110
+ Rails.boot!