skynet 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/History.txt +49 -0
  2. data/Manifest.txt +84 -6
  3. data/README.txt +75 -64
  4. data/app_generators/skynet_install/skynet_install_generator.rb +14 -8
  5. data/app_generators/skynet_install/templates/migration.rb +1 -24
  6. data/app_generators/skynet_install/templates/skynet_config.rb +50 -0
  7. data/app_generators/skynet_install/templates/skynet_initializer.rb +1 -0
  8. data/app_generators/skynet_install/templates/{skynet_schema.sql → skynet_mysql_schema.sql} +1 -24
  9. data/bin/skynet +37 -10
  10. data/bin/skynet_install +5 -5
  11. data/bin/skynet_tuplespace_server +27 -19
  12. data/examples/dgrep/README +70 -0
  13. data/examples/dgrep/config/skynet_config.rb +26 -0
  14. data/examples/dgrep/data/shakespeare/README +2 -0
  15. data/examples/dgrep/data/shakespeare/poetry/loverscomplaint +381 -0
  16. data/examples/dgrep/data/shakespeare/poetry/rapeoflucrece +2199 -0
  17. data/examples/dgrep/data/shakespeare/poetry/sonnets +2633 -0
  18. data/examples/dgrep/data/shakespeare/poetry/various +640 -0
  19. data/examples/dgrep/data/shakespeare/poetry/venusandadonis +1423 -0
  20. data/examples/dgrep/data/testfile1.txt +1 -0
  21. data/examples/dgrep/data/testfile2.txt +1 -0
  22. data/examples/dgrep/data/testfile3.txt +1 -0
  23. data/examples/dgrep/data/testfile4.txt +1 -0
  24. data/examples/dgrep/lib/dgrep.rb +59 -0
  25. data/examples/dgrep/lib/mapreduce_test.rb +32 -0
  26. data/examples/dgrep/lib/most_common_words.rb +45 -0
  27. data/examples/dgrep/script/dgrep +75 -0
  28. data/examples/rails_mysql_example/README +66 -0
  29. data/examples/rails_mysql_example/Rakefile +10 -0
  30. data/examples/rails_mysql_example/app/controllers/application.rb +10 -0
  31. data/examples/rails_mysql_example/app/helpers/application_helper.rb +3 -0
  32. data/examples/rails_mysql_example/app/models/user.rb +21 -0
  33. data/examples/rails_mysql_example/app/models/user_favorite.rb +5 -0
  34. data/examples/rails_mysql_example/app/models/user_mailer.rb +12 -0
  35. data/examples/rails_mysql_example/app/views/user_mailer/welcome.erb +5 -0
  36. data/examples/rails_mysql_example/config/boot.rb +109 -0
  37. data/examples/rails_mysql_example/config/database.yml +42 -0
  38. data/examples/rails_mysql_example/config/environment.rb +59 -0
  39. data/examples/rails_mysql_example/config/environments/development.rb +18 -0
  40. data/examples/rails_mysql_example/config/environments/production.rb +19 -0
  41. data/examples/rails_mysql_example/config/environments/test.rb +22 -0
  42. data/examples/rails_mysql_example/config/initializers/inflections.rb +10 -0
  43. data/examples/rails_mysql_example/config/initializers/mime_types.rb +5 -0
  44. data/examples/rails_mysql_example/config/initializers/skynet.rb +1 -0
  45. data/examples/rails_mysql_example/config/routes.rb +35 -0
  46. data/examples/rails_mysql_example/config/skynet_config.rb +36 -0
  47. data/examples/rails_mysql_example/db/migrate/001_create_skynet_tables.rb +43 -0
  48. data/examples/rails_mysql_example/db/migrate/002_create_users.rb +16 -0
  49. data/examples/rails_mysql_example/db/migrate/003_create_user_favorites.rb +14 -0
  50. data/examples/rails_mysql_example/db/schema.rb +85 -0
  51. data/examples/rails_mysql_example/db/skynet_mysql_schema.sql +33 -0
  52. data/examples/rails_mysql_example/doc/README_FOR_APP +2 -0
  53. data/examples/rails_mysql_example/lib/tasks/rails_mysql_example.rake +20 -0
  54. data/examples/rails_mysql_example/public/.htaccess +40 -0
  55. data/examples/rails_mysql_example/public/404.html +30 -0
  56. data/examples/rails_mysql_example/public/422.html +30 -0
  57. data/examples/rails_mysql_example/public/500.html +30 -0
  58. data/examples/rails_mysql_example/public/dispatch.cgi +10 -0
  59. data/examples/rails_mysql_example/public/dispatch.fcgi +24 -0
  60. data/examples/rails_mysql_example/public/dispatch.rb +10 -0
  61. data/{log/debug.log → examples/rails_mysql_example/public/favicon.ico} +0 -0
  62. data/examples/rails_mysql_example/public/images/rails.png +0 -0
  63. data/examples/rails_mysql_example/public/index.html +277 -0
  64. data/examples/rails_mysql_example/public/javascripts/application.js +2 -0
  65. data/examples/rails_mysql_example/public/javascripts/controls.js +963 -0
  66. data/examples/rails_mysql_example/public/javascripts/dragdrop.js +972 -0
  67. data/examples/rails_mysql_example/public/javascripts/effects.js +1120 -0
  68. data/examples/rails_mysql_example/public/javascripts/prototype.js +4225 -0
  69. data/examples/rails_mysql_example/public/robots.txt +5 -0
  70. data/examples/rails_mysql_example/script/about +3 -0
  71. data/examples/rails_mysql_example/script/console +3 -0
  72. data/examples/rails_mysql_example/script/destroy +3 -0
  73. data/examples/rails_mysql_example/script/generate +3 -0
  74. data/examples/rails_mysql_example/script/performance/benchmarker +3 -0
  75. data/examples/rails_mysql_example/script/performance/profiler +3 -0
  76. data/examples/rails_mysql_example/script/performance/request +3 -0
  77. data/examples/rails_mysql_example/script/plugin +3 -0
  78. data/examples/rails_mysql_example/script/process/inspector +3 -0
  79. data/examples/rails_mysql_example/script/process/reaper +3 -0
  80. data/examples/rails_mysql_example/script/process/spawner +3 -0
  81. data/examples/rails_mysql_example/script/runner +3 -0
  82. data/examples/rails_mysql_example/script/server +3 -0
  83. data/examples/rails_mysql_example/test/fixtures/user_favorites.yml +9 -0
  84. data/examples/rails_mysql_example/test/fixtures/users.yml +11 -0
  85. data/examples/rails_mysql_example/test/test_helper.rb +38 -0
  86. data/examples/rails_mysql_example/test/unit/user_favorite_test.rb +8 -0
  87. data/examples/rails_mysql_example/test/unit/user_test.rb +8 -0
  88. data/extras/README +7 -0
  89. data/extras/init.d/skynet +87 -0
  90. data/extras/nagios/check_skynet.sh +121 -0
  91. data/extras/rails/controllers/skynet_controller.rb +43 -0
  92. data/extras/rails/views/skynet/index.rhtml +137 -0
  93. data/lib/skynet.rb +59 -1
  94. data/lib/skynet/mapreduce_helper.rb +2 -2
  95. data/lib/skynet/mapreduce_test.rb +32 -1
  96. data/lib/skynet/message_queue_adapters/mysql.rb +422 -539
  97. data/lib/skynet/message_queue_adapters/tuple_space.rb +45 -71
  98. data/lib/skynet/skynet_active_record_extensions.rb +22 -11
  99. data/lib/skynet/skynet_config.rb +54 -20
  100. data/lib/skynet/skynet_console.rb +4 -1
  101. data/lib/skynet/skynet_console_helper.rb +5 -1
  102. data/lib/skynet/skynet_debugger.rb +58 -4
  103. data/lib/skynet/skynet_job.rb +61 -24
  104. data/lib/skynet/skynet_launcher.rb +29 -3
  105. data/lib/skynet/skynet_logger.rb +11 -1
  106. data/lib/skynet/skynet_manager.rb +403 -240
  107. data/lib/skynet/skynet_message.rb +1 -3
  108. data/lib/skynet/skynet_message_queue.rb +42 -19
  109. data/lib/skynet/skynet_partitioners.rb +19 -15
  110. data/lib/skynet/skynet_ruby_extensions.rb +18 -0
  111. data/lib/skynet/skynet_tuplespace_server.rb +17 -14
  112. data/lib/skynet/skynet_worker.rb +132 -98
  113. data/lib/skynet/version.rb +1 -1
  114. data/script/destroy +0 -0
  115. data/script/generate +0 -0
  116. data/script/txt2html +0 -0
  117. data/test/test_helper.rb +2 -0
  118. data/test/test_skynet.rb +13 -5
  119. data/test/test_skynet_manager.rb +24 -9
  120. data/test/test_skynet_task.rb +1 -1
  121. data/website/index.html +77 -29
  122. data/website/index.txt +53 -24
  123. data/website/stylesheets/screen.css +12 -12
  124. metadata +156 -66
  125. data/app_generators/skynet_install/templates/skynet +0 -46
  126. data/log/skynet.log +0 -29
  127. data/log/skynet_tuplespace_server.log +0 -7
  128. data/log/skynet_worker.pid +0 -1
@@ -0,0 +1 @@
1
+ This is a test file with some data
@@ -0,0 +1 @@
1
+ Another file with more data and more data
@@ -0,0 +1 @@
1
+ One more file with no D ata
@@ -0,0 +1 @@
1
+ Some thing data
@@ -0,0 +1,59 @@
1
+ class Dgrep
2
+ include SkynetDebugger
3
+
4
+ # Takes an array that looks like [ [filename1,["word1","word2"]], [filename2,["word1","word2"]] ]
5
+ # Returns an array that looks like [ [word1, cnt], [word2,cnt], [word1, cnt] ]
6
+ # Map gets an array and should return an array
7
+ def self.map(map_datas)
8
+ results = []
9
+ map_datas.each do |filename,words|
10
+ begin
11
+ words.each do |word|
12
+ cnt = File.read(filename).scan(/\W#{word}\W/i).size
13
+ results << [word,cnt] if cnt and cnt > 0
14
+ end
15
+ rescue Errno::EISDIR
16
+ # skip directories
17
+ end
18
+ end
19
+ return results if results.any?
20
+ end
21
+
22
+ # The chosen reduce partiioner attempts group keys by partition. For example, if you choose 2 words and 2 reducers it will make sure
23
+ # the first word goes to the first reducer and the second word to the second reducer. If you only have 1 reducer (the defaukt)
24
+ # It doesn't bother partitioning. You can write as complex a partiioner as you'd like.
25
+ def self.reduce_partition(post_map_data,new_partitions)
26
+ Skynet::Partitioners::ArrayDataSplitByFirstEntry.reduce_partition(post_map_data,new_partitions)
27
+
28
+ ## I've included the contents of the above method so you can see how to write a reduce_partitioner
29
+ # partitions = []
30
+ # (0..new_partitions - 1).each { |i| partitions[i] = Array.new }
31
+ # keys_seen = {}
32
+ # post_map_data.each do |partition|
33
+ # partition.each do |array|
34
+ # next unless array.is_a?(Array) and array.size >= 2
35
+ # if array[0].kind_of?(Fixnum)
36
+ # key = array[0]
37
+ # else
38
+ # keys_seen[array[0]] ||= keys_seen.keys.size
39
+ # key = keys_seen[array[0]]
40
+ # end
41
+ # partitions[key % new_partitions] << array
42
+ # end
43
+ # end
44
+ # partitions
45
+
46
+ end
47
+
48
+ # Takes an array that looks like [ [word1, cnt], [word2,cnt], [word1, cnt] ]
49
+ # reduce also gets an array
50
+ def self.reduce(reduce_datas)
51
+ results = {}
52
+ reduce_datas.each do |reduce_data|
53
+ results[reduce_data[0]] ||= 0
54
+ results[reduce_data[0]] += reduce_data[1]
55
+ end
56
+ results
57
+ end
58
+
59
+ end
@@ -0,0 +1,32 @@
1
+ class MapreduceTest
2
+
3
+ include SkynetDebugger
4
+
5
+ def self.run
6
+ job = Skynet::Job.new(
7
+ :mappers => 2,
8
+ :reducers => 1,
9
+ :map_reduce_class => self,
10
+ :map_data => [OpenStruct.new({:created_by => 2}),OpenStruct.new({:created_by => 2}),OpenStruct.new({:created_by => 3})]
11
+ )
12
+ results = job.run
13
+ end
14
+
15
+ def self.map(profiles)
16
+ result = Array.new
17
+ profiles.each do |profile|
18
+ result << [profile.created_by, 1] if profile.created_by
19
+ end
20
+ result
21
+ end
22
+
23
+ def self.reduce(pairs)
24
+ totals = Hash.new
25
+ pairs.each do |pair|
26
+ created_by, count = pair[0], pair[1]
27
+ totals[created_by] ||= 0
28
+ totals[created_by] += count
29
+ end
30
+ totals
31
+ end
32
+ end
@@ -0,0 +1,45 @@
1
+ class MostCommonWords
2
+ include SkynetDebugger
3
+
4
+ def self.map(map_datas)
5
+ results = Hash.new(0)
6
+ map_datas.each do |filename|
7
+ begin
8
+ File.open(filename).each_word do |word|
9
+ next if word.length <= 5
10
+ results[word.downcase] += 1
11
+ end
12
+ rescue Errno::EISDIR
13
+ # skip directories
14
+ end
15
+ end
16
+ ## For efficiency. Not 100% accurate.
17
+ results.sort{|a,b| a[1]<=>b[1]}.reverse.first(100)
18
+ end
19
+
20
+ # The chosen reduce partiioner attempts group keys by partition. For example, if you choose 2 words and 2 reducers it will make sure
21
+ # the first word goes to the first reducer and the second word to the second reducer. If you only have 1 reducer (the defaukt)
22
+ # It doesn't bother partitioning. You can write as complex a partiioner as you'd like.
23
+ def self.reduce_partition(post_map_data,new_partitions)
24
+ Skynet::Partitioners::ArrayDataSplitByFirstEntry.reduce_partition(post_map_data,new_partitions)
25
+ end
26
+
27
+ # Takes an array that looks like [ [word1, cnt], [word2,cnt], [word1, cnt] ]
28
+ # reduce also gets an array
29
+ def self.reduce(reduce_datas)
30
+ results = Hash.new(0)
31
+ reduce_datas.each do |reduce_data|
32
+ results[reduce_data[0]] += reduce_data[1]
33
+ end
34
+ results.sort{|a,b| a[1]<=>b[1]}.reverse.first(10).sort
35
+ end
36
+
37
+ end
38
+
39
+ class IO
40
+ def each_word(&b)
41
+ each do |line|
42
+ line.scan(/\w+/, &b)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+ # USAGE:
3
+ #
4
+ # You can provide one or more words. The last argument is the directory.
5
+ #
6
+ # Eg:
7
+ #
8
+ # ruby ./script/dgrep [-r] word1 word2 word3 directory
9
+ #
10
+ # Passing -r means search recursively
11
+ #
12
+ # Most Common Words
13
+ # I've included a second demo in the form of:
14
+ # ruby ./script/dgrep -r -mcw directory
15
+ # This will return the top 10 most common 5 or more letter words
16
+ #
17
+ # You can also choose to distribute the reduce step by passing --reducers=2 (or any other number. 1 is the default)
18
+
19
+ require 'rubygems'
20
+ require 'rdoc/usage'
21
+ require 'skynet'
22
+ require File.dirname(__FILE__) + '/../config/skynet_config.rb'
23
+
24
+ puts "LOGGING TO #{Skynet.config.logfile_location}"
25
+
26
+ RDoc::usage if ARGV.empty? or ARGV.include?("--help")
27
+
28
+ reducers = 1
29
+ if reduce_arg = ARGV.detect {|i| i =~ /--reducers/ }
30
+ reducers = reduce_arg.split('=').last.to_i
31
+ ARGV.delete_if {|i| i =~ /--reducers/ }
32
+ end
33
+
34
+ user_dir = ARGV.pop
35
+ directory = File.expand_path(user_dir)
36
+
37
+ mcw = ARGV.delete('-mcw') ? true : false
38
+
39
+ files = if ARGV.delete('-r')
40
+ Dir["#{directory}/**/*"]
41
+ else
42
+ Dir["#{directory}/*"]
43
+ end
44
+
45
+ if files.empty?
46
+ puts "No files in #{user_dir}"
47
+ exit
48
+ end
49
+
50
+ words = ARGV
51
+
52
+ results = []
53
+ if mcw
54
+ puts "Looking for the most common words in #{user_dir}"
55
+ results = files.mapreduce(MostCommonWords, :reducers => reducers, :master_timeout => 60)
56
+ if results and results.any?
57
+ puts "RESULTS:"
58
+ results.sort_by{|a| a[1]}.reverse.each_with_index do |a,ii|
59
+ puts "#{ii}. #{a[1]} #{a[0]}"
60
+ end
61
+ else
62
+ puts "No results"
63
+ end
64
+ else
65
+ map_data = files.collect{|file| [file,words]}
66
+ puts "Looking at all the files in #{user_dir} for the word or words '#{words.join(',')}'"
67
+ results = map_data.mapreduce(Dgrep, :data_debug => true)
68
+ if results and results.any?
69
+ results.sort_by{|a| a[1]}.reverse.each_with_index do |a,ii|
70
+ puts "#{ii}. #{a[1]} #{a[0]}"
71
+ end
72
+ else
73
+ puts "No results"
74
+ end
75
+ end
@@ -0,0 +1,66 @@
1
+ ========================
2
+ = Skynet Rails Example =
3
+ ========================
4
+
5
+ Below you'll find a few example skynet uses within a rails application.
6
+ Rails itself is not included in the app so you will need Rails 2 installed locally.
7
+ You will also need to have mysql running locally. If you have special permissions, please edit config/database.yml.
8
+
9
+ SETUP
10
+ -------------------------------------
11
+ > rake db:create
12
+ > rake db:migrate
13
+ > rake db:initialize_defaults
14
+
15
+
16
+ EXAMPLE 1: Complex Migrations
17
+ -------------------------------------
18
+ Lets say we were storing the user's favorites in a single comma separated field in the users table, but want
19
+ to normalize it into a user_favorites table. This is something that would be difficult to do in straight SQL.
20
+ We have a method in our User model to migrate a single user. All we have to do is run it on every user.
21
+
22
+ I added a rake task to run the skynet migration
23
+ > rake db:migrate_favorites
24
+
25
+ You can also choose to run the command (or other commands) yourself in the skynet console
26
+
27
+ > ruby script/skynet console
28
+ console> User.distributed_find(:all).map(:migrate_favorites)
29
+ console> u = User.find(:first)
30
+ console> u.user_favorites.size
31
+
32
+ If you want to re-run the example, remember to run rake db:initialize_defaults again.
33
+
34
+
35
+
36
+ Example 2: Sending Email Asyncronously
37
+ -------------------------------------
38
+ > ruby script/skynet console
39
+ console> u = User.find(:first)
40
+ console> u.send_welcome_email
41
+ # pauses 5 seconds while the user goes to another site and never comes back We don't want that!
42
+ # try again
43
+ console> u.send_later(:send_welcome_email)
44
+ # returns immediately, but sends the email after 5 seconds anyway
45
+
46
+ This sample application was created by creating in the following way
47
+
48
+ 1. Create new rails app
49
+ > rails -d mysql rails_mysql_example
50
+
51
+ 2. Install Skynet with rails and mysql support
52
+ > skynet_install --rails --mysql
53
+
54
+ 3. Run skynet migrations
55
+ > rake db:migrate
56
+
57
+ 4. Create other migrations models
58
+ > ./script/generate model user name:string password:string favorites:string email:string
59
+ > ./script/generate model user_favorite user_id:integer favorite:string
60
+
61
+ ------------------------------------------------------
62
+ If you'd like get a peak at what Skynet is doing, edit ./script/skynet and set
63
+
64
+ Skynet::CONFIG[:SKYNET_LOG_LEVEL] = Logger::INFO # or Logger::INFO
65
+
66
+ and tail ./log/skynet_development.log
@@ -0,0 +1,10 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ require 'tasks/rails'
@@ -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 => '8a54ccda625a3eeb4b2746aaaa094406'
10
+ 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,21 @@
1
+ class User < ActiveRecord::Base
2
+
3
+ has_many :user_favorites, :dependent => :destroy
4
+
5
+ # Moves comma seperated column into seperate relationship table
6
+ def migrate_favorites
7
+ return unless self.favorites
8
+ self.favorites.split(",").each do |favorite|
9
+ self.user_favorites.create(:favorite => favorite)
10
+ end
11
+ self.favorites = nil
12
+ self.save
13
+ end
14
+
15
+ # Slow running welcome email sender
16
+ def send_welcome_email
17
+ sleep 5
18
+ UserMailer.deliver_welcome(self)
19
+ end
20
+ end
21
+
@@ -0,0 +1,5 @@
1
+ class UserFavorite < ActiveRecord::Base
2
+
3
+ belongs_to :user
4
+
5
+ end
@@ -0,0 +1,12 @@
1
+ class UserMailer < ActionMailer::Base
2
+ class Error < StandardError; end
3
+
4
+ def welcome(user)
5
+ @recipients = "#{user.email}"
6
+ @from = "Mycompany <root@localhost>"
7
+ @sent_on = Time.now
8
+ @subject = 'Your account has been activated!'
9
+ @body[:url] = "http://localhost:3000/"
10
+ @body[:user] = user
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ Dear <%= @user.name %>,
2
+
3
+ Welcome to this site!
4
+
5
+ <%= @url %>
@@ -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!