fdietz-ruby-config 0.5.0 → 0.6.0

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.
data/README.md CHANGED
@@ -102,8 +102,7 @@ OS X comes with an already installed Java version.
102
102
  Use apt-get to install the essential packages:
103
103
 
104
104
  sudo apt-get install sun-java6-jre sun-java6-jdk
105
-
106
-
105
+
107
106
  ## Kudos
108
107
 
109
108
  Thanks to Relevance for their work on [Ruby Switcher](http://github.com/relevance/etc/blob/3d607c8ac2f76077f27c3cbc0140b04a89f546be/bash/ruby_switcher.sh) which I used as the basis for the installation of various Ruby Runtimes.
data/ReleaseNotes.md ADDED
@@ -0,0 +1,10 @@
1
+ # Ruby-Config Release Notes
2
+
3
+ ## ruby-config 0.6
4
+ * Set GEM_HOME correctly when installing new gems
5
+ * Ensure that ruby-config gem is installed on each runtime gem path
6
+
7
+ ## ruby-config 0.5
8
+ * Added support for Ruby 1.8.6
9
+ * Added support for Ruby 1.8.7
10
+ * Added support for Ruby 1.9.1
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.6.0
@@ -3,15 +3,21 @@ module RubyConfig
3
3
 
4
4
  attr_accessor :hash
5
5
 
6
- DEFAULTS = {'default' => 'ruby-leopard-1.8.6'}
6
+ #DEFAULTS = { 'default' => 'ruby-leopard-1.8.6' }
7
7
 
8
8
  def initialize(path)
9
9
  @config_file = File.join(path, "config.yml")
10
- File.exist?(@config_file) ? load : @hash = {}.merge(DEFAULTS)
11
-
12
- #puts "config: #{@hash.inspect}"
10
+ File.exist?(@config_file) ? load : @hash = {}#.merge(DEFAULTS)
13
11
  end
14
12
 
13
+ def default_handle
14
+ get('default')
15
+ end
16
+
17
+ def default_handle=(handle)
18
+ set('default', handle)
19
+ end
20
+
15
21
  def get(key)
16
22
  @hash[key]
17
23
  end
@@ -21,11 +27,11 @@ module RubyConfig
21
27
  end
22
28
 
23
29
  def save
24
- RubyConfig::FileHelper.store_yml(@config_file, @hash)
30
+ File.open(@config_file, 'w') { |out| YAML.dump( @hash, out ) }
25
31
  end
26
32
 
27
33
  def load
28
- @hash = RubyConfig::FileHelper.load_yml(@config_file)
34
+ @hash = File.open(@config_file) { |yf| YAML::load( yf ) }
29
35
  end
30
36
 
31
37
  def to_hash
@@ -0,0 +1,63 @@
1
+ require 'ruby_config/rubygems'
2
+
3
+ module RubyConfig
4
+
5
+ class Installer
6
+
7
+ RUBY_CONFIG_GEM_NAME = 'fdietz-ruby-config'
8
+
9
+ attr_reader :rubygems
10
+
11
+ def initialize(ruby_config_path)
12
+ @ruby_config_path = ruby_config_path
13
+ @rubygems = RubyConfig::Rubygems.new(ruby_config_path)
14
+
15
+ ensure_config_directory_exists
16
+ end
17
+
18
+ def install(runtime)
19
+ runtime.do_install
20
+
21
+ # TOOD: only cleanup runtime-specific files
22
+ cleanup_tmp_dir
23
+ end
24
+
25
+ def post_install(runtime)
26
+ @rubygems.install(runtime) unless runtime.rubygems_installed?
27
+
28
+ runtime.post_install
29
+
30
+ # install thyself
31
+ @rubygems.gem_install(RUBY_CONFIG_GEM_NAME)
32
+
33
+ runtime.runtime_specific_gems.each { |gem| @rubygems.gem_install(gem) }
34
+ end
35
+
36
+ def runtime_install_path
37
+ File.join(@ruby_config_path, 'runtimes')
38
+ end
39
+
40
+ def tmp_path
41
+ File.join(@ruby_config_path, 'tmp')
42
+ end
43
+
44
+ private
45
+
46
+ def cleanup_tmp_dir
47
+ empty_dir(tmp_path)
48
+ end
49
+
50
+ def empty_dir(path)
51
+ Dir[File.join(path, '*')].each do |file|
52
+ FileUtils.remove_entry_secure(file) if Pathname.new(file).directory?
53
+ end
54
+ end
55
+
56
+ def ensure_config_directory_exists
57
+ FileUtils.mkdir_p(@ruby_config_path)
58
+ FileUtils.mkdir_p(tmp_path)
59
+ FileUtils.mkdir_p(runtime_install_path)
60
+ end
61
+
62
+ end
63
+ end
@@ -1,5 +1,7 @@
1
1
  require 'ruby_config/config'
2
- require 'ruby_config/file_helper'
2
+ require 'ruby_config/runtime_base'
3
+
4
+ Dir.glob(File.join(File.dirname(__FILE__), 'runtimes/*.rb')).each {|f| require f }
3
5
 
4
6
  module RubyConfig
5
7
 
@@ -9,92 +11,54 @@ module RubyConfig
9
11
 
10
12
  def initialize(ruby_config_path)
11
13
  @ruby_config_path = ruby_config_path
12
- @runtime_install_path = File.join(ruby_config_path, "runtimes")
13
- @tmp_path = File.join(ruby_config_path, "tmp")
14
-
15
- @config = RubyConfig::Config.new(@ruby_config_path)
16
-
17
- @list = []
18
- ensure_config_directory_exists
19
- end
20
-
21
- def add(runtime_const)
22
- @list << runtime_const.new(@runtime_install_path, @tmp_path)
14
+ load_available_runtimes.each { |runtime| add(runtime) }
23
15
  end
24
16
 
25
- def default?(handle)
26
- handle == default_handle
27
- end
28
-
29
- def first
30
- @list.first
17
+ def list
18
+ @list ||= []
31
19
  end
32
20
 
33
- def exist?(handle)
21
+ def add(runtime_const)
22
+ list << runtime_const.new(runtime_install_path, tmp_path)
23
+ end
24
+
25
+ def exists?(handle)
34
26
  !!get(handle)
35
27
  end
36
28
 
37
29
  def get(handle)
38
30
  handle_int = handle.to_i # returns 0 if no fixnum
39
- if handle_int > 0 && handle_int << @list.size
40
- @list.values_at(handle_int-1).first
31
+ if handle_int > 0 && handle_int << list.size
32
+ list.values_at(handle_int-1).first
41
33
  else
42
- @list.find { |item| item.handle == handle }
34
+ list.find { |item| item.handle == handle }
43
35
  end
44
36
  end
45
37
 
46
38
  def list_available
47
- @list
39
+ list
48
40
  end
49
41
 
50
42
  def list_installed
51
- @list.find_all { |item| item.already_installed?}
52
- end
53
-
54
- def install(runtime)
55
- runtime.do_install unless runtime.already_installed?
56
-
57
- use(runtime)
58
-
59
- runtime.do_post_install
60
-
61
- runtime
43
+ list.find_all { |item| item.already_installed?}
62
44
  end
63
-
64
- def use(runtime)
65
- set_default_handle(runtime.handle)
66
- @config.save
67
-
68
- set_symlinks_to_runtime(runtime)
69
-
70
- runtime
71
- end
72
-
45
+
73
46
  private
74
-
75
- def set_symlinks_to_runtime(runtime)
76
- ruby_path = File.join(@ruby_config_path, "ruby")
77
- gem_path = File.join(@ruby_config_path, "gem")
78
- RubyConfig::FileHelper.delete_file(ruby_path)
79
- RubyConfig::FileHelper.delete_file(gem_path)
80
- RubyConfig::FileHelper.set_symlink(runtime.ruby_home_path, ruby_path)
81
- RubyConfig::FileHelper.set_symlink(runtime.gem_home_path, gem_path)
82
- end
47
+
48
+ def load_available_runtimes
49
+ [ RubyConfig::Runtimes::LeopardRuntime, RubyConfig::Runtimes::RubyEnterpriseEditionRuntime,
50
+ RubyConfig::Runtimes::JRubyRuntime, RubyConfig::Runtimes::Ruby19Runtime,
51
+ RubyConfig::Runtimes::Ruby186Runtime, RubyConfig::Runtimes::Ruby187Runtime
52
+ ]
53
+ end
83
54
 
84
- def default_handle
85
- @config.get("default")
86
- end
87
-
88
- def set_default_handle(default_handle)
89
- @config.set("default", default_handle)
90
- end
55
+ def runtime_install_path
56
+ File.join(@ruby_config_path, 'runtimes')
57
+ end
91
58
 
92
- def ensure_config_directory_exists
93
- FileUtils.mkdir_p(@ruby_config_path)
94
- FileUtils.mkdir_p(@tmp_path)
95
- FileUtils.mkdir_p(@runtime_install_path)
96
- end
97
-
59
+ def tmp_path
60
+ File.join(@ruby_config_path, 'tmp')
61
+ end
62
+
98
63
  end
99
-
100
64
  end
@@ -0,0 +1,61 @@
1
+ module RubyConfig
2
+
3
+ class Rubygems
4
+
5
+ VERSION = "1.3.5"
6
+ ARCHIVE_NAME = "rubygems-#{VERSION}"
7
+ ARCHIVE_FILE_NAME = "#{ARCHIVE_NAME}.tgz"
8
+ DOWNLOAD_URL = "http://rubyforge.org/frs/download.php/60718/#{ARCHIVE_FILE_NAME}"
9
+
10
+ def initialize(ruby_config_path)
11
+ @ruby_config_path = ruby_config_path
12
+ end
13
+
14
+ def install(runtime)
15
+ download_file(DOWNLOAD_URL, archive_file_name) unless archive_exists?
16
+
17
+ extract_tar_gz(archive_file_name, tmp_path)
18
+
19
+ ruby_gems_setup(archive_path, runtime.ruby_executable_path, runtime.additional_library_path)
20
+ end
21
+
22
+ def gem_install(gem_technical_name)
23
+ gem_executable_path = File.join(@ruby_config_path, 'gem')
24
+ system "GEM_HOME=#{gem_executable_path} gem install -q --no-ri --no-rdoc #{gem_technical_name}"
25
+ end
26
+
27
+ private
28
+
29
+ # system("ruby setup.rb --prefix=#{additional_library_path}")
30
+ def ruby_gems_setup(path, ruby_executable_path, additional_library_path)
31
+ FileUtils.cd(path)
32
+ puts "ruby executable path: #{ruby_executable_path}"
33
+ system("#{ruby_executable_path} setup.rb --prefix=#{additional_library_path}")
34
+ end
35
+
36
+ def extract_tar_gz(tgz_archive_path, destination_path)
37
+ system("tar xfvz #{tgz_archive_path} -C #{destination_path}")
38
+ end
39
+
40
+ def tmp_path
41
+ File.join(@ruby_config_path, 'tmp')
42
+ end
43
+
44
+ def archive_file_name
45
+ File.join(tmp_path, ARCHIVE_FILE_NAME)
46
+ end
47
+
48
+ def archive_path
49
+ File.join(tmp_path, ARCHIVE_NAME)
50
+ end
51
+
52
+ def archive_exists?
53
+ File.exist?(archive_path)
54
+ end
55
+
56
+ def download_file(url, destination_path)
57
+ system("wget #{url} --output-document=#{destination_path}")
58
+ end
59
+
60
+ end
61
+ end
@@ -1,8 +1,9 @@
1
+ require 'ruby_config/registry'
1
2
  require 'ruby_config/runtime_base'
2
3
  require 'ruby_config/options_parser'
3
4
  require 'ruby_config/profile_config'
4
-
5
- Dir.glob(File.join(File.dirname(__FILE__), 'runtimes/*.rb')).each {|f| require f }
5
+ require 'ruby_config/installer'
6
+ require 'ruby_config/switcher'
6
7
 
7
8
  module RubyConfig
8
9
 
@@ -11,8 +12,11 @@ module RubyConfig
11
12
  RUBY_CONFIG_PATH = File.join(ENV['HOME'], ".ruby-config")
12
13
 
13
14
  def initialize
14
- @registry = RubyConfig::Registry.new(RUBY_CONFIG_PATH)
15
- load_available_runtimes.each { |runtime| @registry.add(runtime) }
15
+ @rubygems = RubyConfig::Rubygems.new(RUBY_CONFIG_PATH)
16
+ @registry = RubyConfig::Registry.new(RUBY_CONFIG_PATH)
17
+ @installer = RubyConfig::Installer.new(RUBY_CONFIG_PATH)
18
+ @switcher = RubyConfig::Switcher.new(RUBY_CONFIG_PATH)
19
+ @config = RubyConfig::Config.new(RUBY_CONFIG_PATH)
16
20
  end
17
21
 
18
22
  def run
@@ -75,12 +79,12 @@ module RubyConfig
75
79
  end
76
80
 
77
81
  def uninstall(handle)
78
- unless @registry.exist?(handle)
82
+ unless @registry.exists?(handle)
79
83
  puts "Unknown ruby runtime: #{handle}."
80
84
  return
81
85
  end
82
-
83
- if @registry.default?(handle)
86
+
87
+ if default?(handle)
84
88
  puts "Can't delete currently selected runtime."
85
89
  return
86
90
  end
@@ -92,46 +96,41 @@ module RubyConfig
92
96
  puts "Done!"
93
97
  end
94
98
  end
95
-
96
- def load_available_runtimes
97
- list = []
98
- list << RubyConfig::Runtimes::LeopardRuntime
99
- list << RubyConfig::Runtimes::RubyEnterpriseEditionRuntime
100
- list << RubyConfig::Runtimes::JRubyRuntime
101
- list << RubyConfig::Runtimes::Ruby19Runtime
102
- list << RubyConfig::Runtimes::Ruby186Runtime
103
- list << RubyConfig::Runtimes::Ruby187Runtime
104
- list
105
- end
106
-
99
+
107
100
  def help(options_parser)
108
101
  print_info_header
109
102
  options_parser.print_help
110
103
  end
111
104
 
112
105
  def install_runtime(handle)
113
- unless @registry.exist?(handle)
106
+ unless @registry.exists?(handle)
114
107
  puts "Unknown ruby runtime: #{handle}"
115
108
  return
116
109
  end
117
110
 
118
111
  runtime = @registry.get(handle)
119
112
 
120
- puts "#{runtime} already installed" if runtime.already_installed?
113
+ if runtime.already_installed?
114
+ puts "#{runtime} already installed"
115
+ else
116
+ @installer.install(runtime)
117
+ @switcher.switch(runtime)
118
+ @installer.post_install(runtime)
119
+
120
+ print_use_results(runtime)
121
+ end
121
122
 
122
- @registry.install(runtime)
123
- print_use_results(runtime)
124
123
  end
125
124
 
126
125
  def use_runtime(handle)
127
- unless @registry.exist?(handle)
126
+ unless @registry.exists?(handle)
128
127
  puts "Unknown ruby runtime: #{handle}"
129
128
  return
130
129
  end
131
130
 
132
131
  runtime = @registry.get(handle)
133
132
 
134
- if @registry.use(runtime)
133
+ if @switcher.switch(runtime)
135
134
  #display_ruby_version
136
135
  #print_use_results(runtime)
137
136
  display_ruby_version(runtime)
@@ -171,7 +170,7 @@ module RubyConfig
171
170
 
172
171
  def print_runtime(index, item)
173
172
  print "#{index+1}) "
174
- print @registry.default?(item.handle) ? "*" : " "
173
+ print default?(item.handle) ? "*" : " "
175
174
  puts " #{item}"
176
175
  end
177
176
 
@@ -180,20 +179,20 @@ module RubyConfig
180
179
  puts " RUBY_HOME=#{runtime.ruby_home_path}"
181
180
  puts " GEM_HOME=#{runtime.gem_home_path}"
182
181
 
183
- unless runtime.bash_alias.empty?
184
- puts "\nalias:"
185
- print_alias(runtime.bash_alias)
186
- end
182
+ # unless runtime.bash_alias.empty?
183
+ # puts "\nalias:"
184
+ # print_alias(runtime.bash_alias)
185
+ # end
187
186
 
188
187
  puts "\nruby -v:"
189
188
  display_system_ruby_version
190
189
  end
191
190
 
192
- def print_alias(hash)
193
- hash.each do |key, value|
194
- puts " alias #{key}=\"#{value}\""
195
- end
196
- end
191
+ # def print_alias(hash)
192
+ # hash.each do |key, value|
193
+ # puts " alias #{key}=\"#{value}\""
194
+ # end
195
+ # end
197
196
 
198
197
  def display_ruby_version(runtime)
199
198
  puts "Running: #{runtime}"
@@ -208,5 +207,9 @@ module RubyConfig
208
207
  exit
209
208
  end
210
209
 
210
+ def default?(handle)
211
+ handle == @config.default_handle
212
+ end
213
+
211
214
  end
212
215
  end
@@ -8,32 +8,28 @@ module RubyConfig
8
8
  @install_path = File.join(install_path, handle)
9
9
  @tmp_path = tmp_path
10
10
  end
11
-
11
+
12
12
  def do_install
13
- create_directory_structure
14
-
15
- download_file_unless_exists(archive_file_name, archive_download_url)
16
-
17
- # runtime specific installation part
13
+ prepare_install
18
14
  install
19
-
20
- cleanup_tmp_dir
21
15
  end
22
-
16
+
17
+ # called after the archive was successfully downloaded to tmp/archive_file_name directory
18
+ # you might want to:
19
+ # * extract archive
20
+ # * configure && make && make install
23
21
  def install
24
22
  raise "Not implemented yet!"
25
23
  end
26
-
27
- def do_post_install
28
- post_install
29
-
30
- install_rubygems unless File.exists?(gem_executable_path)
31
-
32
- # install thyselve
33
- #install_gem('ruby-config')
34
- end
35
24
 
36
- # called after install and runtime is enabled
25
+ # called after:
26
+ # * runtime.install
27
+ # * switch to newly installed runtime
28
+ # * rubygems installation
29
+ #
30
+ # you might want to:
31
+ # * install additional rubygems
32
+ # * set symlinks
37
33
  def post_install
38
34
  end
39
35
 
@@ -56,13 +52,19 @@ module RubyConfig
56
52
  raise "Not implemented yet!"
57
53
  end
58
54
 
55
+ # optional
56
+ # Array of gem names of type string
57
+ def runtime_specific_gems
58
+ []
59
+ end
60
+
59
61
  # example: 1.8 or 1.9
60
62
  def major_version
61
63
  '1.8'
62
64
  end
63
65
 
64
66
  # hash (key: alias name, value: alias bash script)
65
- def bash_alias;{};end
67
+ # def bash_alias;{};end
66
68
 
67
69
  def ruby_home_path
68
70
  File.join(@install_path, 'ruby')
@@ -104,60 +106,44 @@ module RubyConfig
104
106
  def delete
105
107
  FileUtils.remove_entry_secure(@install_path)
106
108
  end
107
-
108
- protected
109
109
 
110
- def install_rubygems
111
- version = "1.3.5"
112
- archive_name = "rubygems-#{version}"
113
- archive_file_name = "#{archive_name}.tgz"
114
- download_url = "http://rubyforge.org/frs/download.php/60718/#{archive_file_name}"
115
-
116
- download_file_unless_exists(archive_file_name, download_url)
117
-
118
- extract_tar_gz(File.join(@tmp_path, archive_file_name), @tmp_path)
119
- FileUtils.cd(File.join(@tmp_path, archive_name))
120
- #system("ruby setup.rb --prefix=#{additional_library_path}")
121
- system("ruby setup.rb")
122
- end
123
-
124
- def cleanup_tmp_dir
125
- empty_dir(@tmp_path)
110
+ def create_directory_structure
111
+ [@install_path, @tmp_path, ruby_home_path, ruby_bin_path, gem_home_path].each do |path|
112
+ FileUtils.mkdir_p(path)
126
113
  end
127
-
128
- def create_directory_structure
129
- FileUtils.mkdir_p(@install_path)
130
- FileUtils.mkdir_p(@tmp_path)
131
- FileUtils.mkdir_p(ruby_home_path)
132
- FileUtils.mkdir_p(ruby_bin_path)
133
- FileUtils.mkdir_p(gem_home_path)
134
- end
135
-
136
- def download_file_unless_exists(archive, url)
137
- archive_path = File.join(@tmp_path, archive)
138
- unless File.exist?(archive_path)
139
- path = download_file_wget(url, archive_path)
140
- puts "#{archive} downloaded successfully to #{archive_path}"
141
- end
114
+ end
115
+
116
+ def archive_path
117
+ File.join(@tmp_path, archive_file_name)
118
+ end
119
+
120
+ def prepare_install
121
+ create_directory_structure
122
+ download_archive unless archive_exists?
123
+ end
124
+
125
+ def rubygems_installed?
126
+ File.exists?(gem_executable_path)
127
+ end
128
+
129
+ private
130
+
131
+ def archive_exists?
132
+ File.exist?(archive_path)
142
133
  end
143
-
144
- def download_file_wget(url, destination_path)
145
- system("wget #{url} --output-document=#{destination_path}")
146
- end
147
134
 
148
- def extract_tar_gz(archive_path, destination_path)
149
- system("tar xfvz #{archive_path} -C #{destination_path}")
150
- end
151
-
152
- def empty_dir(path)
153
- Dir[File.join(path, '*')].each do |file|
154
- FileUtils.remove_entry_secure(file) if Pathname.new(file).directory?
155
- end
156
- end
135
+ def download_archive
136
+ download_file(archive_download_url, archive_path)
137
+ end
138
+
139
+ def download_file(url, destination_path)
140
+ system("wget #{url} --output-document=#{destination_path}")
141
+ end
142
+
143
+ def extract_tar_gz(archive_path, destination_path)
144
+ system("tar xfvz #{archive_path} -C #{destination_path}")
145
+ end
157
146
 
158
- def gem_install(gem_technical_name)
159
- system "gem install -q --no-ri --no-rdoc #{gem_technical_name}"
160
- end
161
147
  end
162
148
 
163
- end
149
+ end
@@ -43,9 +43,12 @@ module RubyConfig
43
43
 
44
44
  def post_install
45
45
  # install_nailgun
46
- install_jruby_specific_gem
47
46
  end
48
-
47
+
48
+ def runtime_specific_gems
49
+ ['rake', 'jruby-openssl']
50
+ end
51
+
49
52
  private
50
53
 
51
54
  def copy_archive_content_to_ruby_directory
@@ -55,16 +58,11 @@ module RubyConfig
55
58
 
56
59
  # there is already a jgem and gem, therefore no symlink required for gem!
57
60
  def set_symlinks_for_jruby_commands
58
- jruby_commands_requiring_symlinks.each do |item|
59
- RubyConfig::FileHelper.set_symlink(item.first, bin_path(item.last))
61
+ %w(ruby irb).each do |item|
62
+ FileUtils.ln_s(bin_path("j#{item}"), bin_path(item))
60
63
  end
61
64
  end
62
-
63
- def jruby_commands_requiring_symlinks
64
- [[bin_path('jruby'), 'ruby' ],
65
- [bin_path('jirb') , 'irb' ]]
66
- end
67
-
65
+
68
66
  # CHECK: can we download an archive which preserves permissions instead?
69
67
  def chmod_executables
70
68
  %w(jruby jgem gem jirb).each { |command| chmod_executable_for_others(bin_path(command)) }
@@ -85,12 +83,7 @@ module RubyConfig
85
83
  FileUtils.cd(nailgun_path)
86
84
  system "#{nailgun_path}/make"
87
85
  end
88
-
89
- def install_jruby_specific_gem
90
- gem_install("rake")
91
- gem_install("jruby-openssl")
92
- end
93
-
86
+
94
87
  end
95
88
 
96
89
  end
@@ -36,6 +36,8 @@ module RubyConfig
36
36
 
37
37
  private
38
38
  def ree_installer
39
+ puts "path= #{File.join(@tmp_path, RUBY_ENTERPRISE_EDITION_DIR)}"
40
+ puts File.exists?(File.join(@tmp_path, RUBY_ENTERPRISE_EDITION_DIR))
39
41
  FileUtils.cd(File.join(@tmp_path, RUBY_ENTERPRISE_EDITION_DIR))
40
42
  system("./installer -a #{@install_path}/ruby --dont-install-useful-gems")
41
43
  end
@@ -0,0 +1,47 @@
1
+ module RubyConfig
2
+
3
+ class Switcher
4
+
5
+ attr_reader :config
6
+
7
+ def initialize(ruby_config_path)
8
+ @ruby_config_path = ruby_config_path
9
+ @config = RubyConfig::Config.new(@ruby_config_path)
10
+ end
11
+
12
+ def switch(runtime)
13
+ set_default_handle(runtime.handle)
14
+ set_symlinks_to_runtime(runtime)
15
+ end
16
+
17
+ def set_symlinks_to_runtime(runtime)
18
+ delete_existing_symlinks
19
+ create_symlinks(runtime)
20
+ end
21
+
22
+ private
23
+ def ruby_path
24
+ File.join(@ruby_config_path, "ruby")
25
+ end
26
+
27
+ def gem_path
28
+ File.join(@ruby_config_path, "gem")
29
+ end
30
+
31
+ def create_symlinks(runtime)
32
+ FileUtils.ln_s(runtime.ruby_home_path, ruby_path)
33
+ FileUtils.ln_s(runtime.gem_home_path, gem_path)
34
+ end
35
+
36
+ def delete_existing_symlinks
37
+ [ruby_path, gem_path].each do |path|
38
+ File.delete(path) if File.exist?(path)
39
+ end
40
+ end
41
+
42
+ def set_default_handle(handle)
43
+ @config.default_handle = handle
44
+ @config.save
45
+ end
46
+ end
47
+ end
data/lib/ruby_config.rb CHANGED
@@ -9,12 +9,12 @@ require 'yaml'
9
9
  require 'highline/import'
10
10
 
11
11
  require 'ruby_config/runner'
12
- require 'ruby_config/registry'
13
- require 'ruby_config/file_helper'
12
+ #require 'ruby_config/registry'
14
13
 
15
14
  module RubyConfig
16
15
  def self.version
17
- RubyConfig::FileHelper.read_content_from_file(File.join(File.dirname(__FILE__), '..', 'VERSION'))
16
+ version_path = File.join(File.dirname(__FILE__), '..', 'VERSION')
17
+ File.open(version_path, "r") { |file| file.read }
18
18
  end
19
19
  end
20
20
 
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class InstallerTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @root = "/tmp/ruby-config"
7
+ FileUtils.mkdir(@root)
8
+
9
+ @runtime = RuntimeBaseTestHelper::RuntimeBaseStub.new(File.join(@root, "install"), File.join(@root, "tmp"))
10
+ @installer = RubyConfig::Installer.new(@root)
11
+ end
12
+
13
+ def teardown
14
+ FileUtils.rm_rf(@root)
15
+ end
16
+
17
+ test "should create config directories" do
18
+ @installer = RubyConfig::Installer.new(@root)
19
+ File.exists?(@installer.runtime_install_path)
20
+ File.exists?(@installer.tmp_path)
21
+ end
22
+
23
+ end
24
+
25
+ module RuntimeBaseTestHelper
26
+ class RuntimeBaseStub < RubyConfig::RuntimeBase
27
+ def install;end
28
+ def archive_file_name;"filename";end
29
+ def archive_download_url;"http://download.com";end
30
+ def handle;"handle";end
31
+ def description;"description";end
32
+ end
33
+ end
@@ -1,103 +1,37 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
- class RegistryInitializeTest < Test::Unit::TestCase
3
+ class RegistryTest < Test::Unit::TestCase
4
4
  def setup
5
- @root = File.join("/tmp", "test")
6
- @registry = RubyConfig::Registry.new(@root)
5
+ @registry = RubyConfig::Registry.new("/tmp/ruby-config")
7
6
  end
8
-
9
- def teardown
10
- FileUtils.rm_rf(@root)
11
- end
12
-
13
- test "should ensure config directories exist" do
14
- assert File.exist?(@root)
15
- assert File.exist?(File.join(@root,"runtimes"))
16
- assert File.exist?(File.join(@root,"tmp"))
7
+
8
+ test "should list all available runtimes" do
9
+ assert_equal 6, @registry.list_available.size
17
10
  end
18
-
19
- end
20
-
21
-
22
- class RegistryInstallTest < Test::Unit::TestCase
23
11
 
24
- def setup
25
- @root = File.join("/tmp", "test")
26
- @registry = RubyConfig::Registry.new(@root)
27
- @registry.add(RegistryTestHelper::RuntimeBaseStub)
28
- @runtime = @registry.get("handle")
12
+ test "should list all installed runtimes" do
13
+ @registry.list.first.expects(:already_installed?).returns(true)
14
+ assert_equal 1, @registry.list_installed.size
29
15
  end
30
16
 
31
- def teardown
32
- FileUtils.rm_rf(@root)
17
+ test "should return runtime based on handle" do
18
+ @registry.add(RubyConfig::Runtimes::LeopardRuntime)
19
+
20
+ assert_equal @registry.list.first, @registry.get('ruby-leopard-1.8.6')
33
21
  end
34
-
35
- test "should install using specific runtime implementation" do
36
- @registry.install(@runtime)
37
22
 
38
- assert File.exist?(@runtime.ruby_home_path)
39
- assert File.exist?(@runtime.gem_home_path)
40
- assert File.exist?(File.join(@runtime.ruby_bin_path, "ruby"))
41
- assert File.exist?(File.join(@runtime.ruby_bin_path, "gem"))
42
- assert File.exist?(File.join(@runtime.ruby_bin_path, "irb"))
43
- end
44
-
45
- test "should make use of installed runtime" do
46
- @registry.expects(:use).with(@runtime)
47
- @registry.install(@runtime)
48
- end
49
-
50
- test "should call post install methods" do
51
- @runtime.expects(:post_install)
52
- @registry.install(@runtime)
23
+ test "should return runtime based on index" do
24
+ @registry.add(RubyConfig::Runtimes::LeopardRuntime)
25
+
26
+ assert_equal @registry.list.first, @registry.get(1)
53
27
  end
54
- end
55
-
56
28
 
57
- class RegistryUseTest < Test::Unit::TestCase
58
-
59
- def setup
60
- @root = File.join("/tmp", "test")
61
- @registry = RubyConfig::Registry.new(@root)
62
- @registry.add(RegistryTestHelper::RuntimeBaseStub)
63
- @runtime = @registry.get("handle")
64
- @registry.install(@runtime)
65
- end
66
-
67
- def teardown
68
- FileUtils.rm_rf(@root)
69
- end
70
-
71
- test "should set default handle in config file" do
72
- @registry.use(@runtime)
29
+ test "should return return true if runtime exists" do
30
+ @registry.add(RubyConfig::Runtimes::LeopardRuntime)
73
31
 
74
- config = File.open(File.join(@registry.ruby_config_path, "config.yml")) { |yf| YAML::load( yf ) }
75
- assert_equal @runtime.handle, config["default"]
32
+ assert @registry.exists?('ruby-leopard-1.8.6')
76
33
  end
77
34
 
78
- test "should create symlinks to installed runtime" do
79
- @registry.use(@runtime)
80
- assert Pathname.new(File.join(@registry.ruby_config_path, "ruby")).symlink?
81
- assert Pathname.new(File.join(@registry.ruby_config_path, "gem")).symlink?
82
- end
83
35
  end
84
36
 
85
- module RegistryTestHelper
86
-
87
- class RuntimeBaseStub < RubyConfig::RuntimeBase
88
- # create fake ruby and gem executables
89
- def install
90
- FileUtils.touch(File.join(ruby_bin_path, "ruby"))
91
- FileUtils.touch(File.join(ruby_bin_path, "gem"))
92
- FileUtils.touch(File.join(ruby_bin_path, "irb"))
93
- end
94
-
95
- def archive_file_name;"archive.zip";end
96
- def archive_download_url;"http://download.com/archive.zip";end
97
- def handle;"handle";end
98
- def description;"description";end
99
- # no download for tests
100
- def download_file_unless_exists(archive, url);end;
101
- end
102
-
103
- end
37
+
@@ -1,102 +1,75 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
- class RuntimeBaseInitializeTest < Test::Unit::TestCase
4
-
5
- test "should set install path" do
6
- r = RuntimeBaseTestHelper::RuntimeBaseStub.new("/install", "/tmp_path")
7
- assert_equal "/install/handle", r.install_path
8
- end
9
- end
3
+ class RuntimeBaseTest < Test::Unit::TestCase
10
4
 
11
- class RuntimeBaseDoInstallTest < Test::Unit::TestCase
12
-
13
5
  def setup
14
- @root = "/tmp/test"
6
+ @root = "/tmp/ruby-config"
15
7
  FileUtils.mkdir(@root)
8
+ FileUtils.mkdir(File.join(@root, 'tmp'))
9
+ @runtime = RuntimeBaseTestHelper::RuntimeBaseStub.new(File.join(@root, "runtimes"), File.join(@root, "tmp"))
16
10
  end
17
-
18
- def teardown
19
- FileUtils.rm_rf(@root)
20
- end
21
-
22
- test "should create directory structure" do
23
- r = RuntimeBaseTestHelper::RuntimeBaseStub.new(File.join(@root, "install"), File.join(@root, "tmp"))
24
- r.stubs(:download_file_unless_exists)
25
- r.do_install
26
-
27
- assert File.exist?(r.install_path)
28
- assert File.exist?(r.tmp_path)
29
- assert File.exist?(File.join(r.install_path,"gem"))
30
- end
31
-
32
- test "should install runtime and cleanup tmp unless installed already" do
33
- r = RuntimeBaseTestHelper::RuntimeBaseStub.new(File.join(@root, "install"), File.join(@root, "tmp"))
34
- r.stubs(:download_file_unless_exists)
35
-
36
- r.expects(:install).once
37
- r.expects(:cleanup_tmp_dir).once
38
- r.do_install
39
- end
40
-
41
- end
42
11
 
43
- class RuntimeBaseDownloadFileUnlessExists < Test::Unit::TestCase
44
-
45
- def setup
46
- @root = "/tmp/test"
47
- FileUtils.mkdir(@root)
48
-
49
- @runtime = RuntimeBaseTestHelper::RuntimeBaseStub.new(File.join(@root, "install"), File.join(@root, "tmp"))
50
- @runtime.send(:create_directory_structure)
51
- end
52
-
53
12
  def teardown
54
13
  FileUtils.rm_rf(@root)
55
14
  end
56
-
57
- test "should download file unless it exist already" do
58
- @runtime.expects(:download_file_wget).once
59
- @runtime.send(:download_file_unless_exists, "archive.zip", "url")
60
- end
61
-
62
- test "should NOT download file if it exists already" do
63
- archive_path = File.join(@runtime.tmp_path, "archive.zip")
64
- FileUtils.touch(archive_path)
65
- @runtime.expects(:download_file_wget).never
66
-
67
- @runtime.send(:download_file_unless_exists, "archive.zip", "url")
68
- end
69
15
 
70
- end
16
+ test "should set install path" do
17
+ r = RuntimeBaseTestHelper::RuntimeBaseStub.new("/install", "/tmp_path")
18
+ assert_equal "/install/handle", r.install_path
19
+ end
71
20
 
72
- class RuntimeBaseIfAlreadyInstalledTest < Test::Unit::TestCase
73
-
74
- def setup
75
- @root = "/tmp/test"
76
- FileUtils.mkdir(@root)
77
-
78
- @runtime = RuntimeBaseTestHelper::RuntimeBaseStub.new(File.join(@root, "install"), File.join(@root, "tmp"))
79
- @runtime.send(:create_directory_structure)
80
- FileUtils.mkdir_p(@runtime.ruby_bin_path)
81
- end
82
-
83
- def teardown
84
- FileUtils.rm_rf(@root)
85
- end
86
-
87
21
  test "should return true if ruby bin found" do
22
+ FileUtils.mkdir_p(File.join(@runtime.ruby_bin_path))
88
23
  bin_path = File.join(@runtime.ruby_bin_path, "ruby")
89
24
  FileUtils.touch(bin_path)
90
-
25
+
91
26
  assert_equal true, @runtime.already_installed?
92
27
  end
93
-
28
+
94
29
  test "should return false if ruby bin NOT found" do
95
30
  assert_equal false, @runtime.already_installed?
96
31
  end
97
-
32
+
33
+ test "should download archive unless it exist already" do
34
+ @runtime.stubs(:create_directory_structure)
35
+
36
+ @runtime.expects(:download_archive)
37
+ @runtime.prepare_install
38
+ end
39
+
40
+ test "should NOT download archive if it exists already" do
41
+ @runtime.stubs(:create_directory_structure)
42
+
43
+ FileUtils.touch(@runtime.archive_path)
44
+
45
+ @runtime.expects(:download_archive).never
46
+ @runtime.prepare_install
47
+ end
48
+
49
+ test "should create initial directory structure" do
50
+ @runtime.create_directory_structure
51
+
52
+ assert File.exists?(@runtime.ruby_bin_path)
53
+ assert File.exists?(@runtime.gem_home_path)
54
+ end
55
+
56
+ test "should delete runtime directories" do
57
+ create_fake_runtime_directories
58
+ @runtime.delete
59
+
60
+ assert !File.exists?(@runtime.ruby_home_path)
61
+ assert !File.exists?(@runtime.gem_home_path)
62
+ end
63
+
64
+ private
65
+ def create_fake_runtime_directories
66
+ FileUtils.mkdir_p(@runtime.ruby_home_path)
67
+ FileUtils.mkdir_p(@runtime.gem_home_path)
68
+ end
69
+
98
70
  end
99
71
 
72
+
100
73
  module RuntimeBaseTestHelper
101
74
  class RuntimeBaseStub < RubyConfig::RuntimeBase
102
75
  def install;end
@@ -0,0 +1,78 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class SwitcherTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @root = "/tmp/ruby-config"
7
+ FileUtils.mkdir(@root)
8
+
9
+ @runtime = RuntimeBaseTestHelper::RuntimeBaseStub.new(File.join(@root, "runtimes"), File.join(@root, "tmp"))
10
+ @switcher = RubyConfig::Switcher.new(@root)
11
+ end
12
+
13
+ def teardown
14
+ FileUtils.rm_rf(@root)
15
+ end
16
+
17
+ test "should set default handle to selected runtime handle" do
18
+ @switcher.config.stubs(:save)
19
+ @switcher.stubs(:set_symlinks_to_runtime)
20
+
21
+ @switcher.switch(@runtime)
22
+
23
+ assert_equal 'handle', @switcher.config.default_handle
24
+ end
25
+
26
+ test "should set symlinks to ruby and gem" do
27
+ @switcher.stubs(:set_default_handle)
28
+ @switcher.stubs(:delete_existing_symlinks)
29
+
30
+ create_fake_ruby_and_gem_directories
31
+ @switcher.switch(@runtime)
32
+
33
+ assert File.exists?(ruby_path)
34
+ assert File.exists?(gem_path)
35
+ end
36
+
37
+ test "should delete obsolete existing symlinks" do
38
+ @switcher.stubs(:set_default_handle)
39
+
40
+ create_fake_ruby_and_gem_directories
41
+ create_fake_ruby_and_gem_symlinks
42
+
43
+ @switcher.switch(@runtime)
44
+ assert File.exists?(ruby_path)
45
+ assert File.exists?(gem_path)
46
+ end
47
+
48
+ private
49
+ def create_fake_ruby_and_gem_directories
50
+ FileUtils.mkdir_p(@runtime.ruby_home_path)
51
+ FileUtils.mkdir_p(@runtime.gem_home_path)
52
+ end
53
+
54
+ def create_fake_ruby_and_gem_symlinks
55
+ FileUtils.ln_s(@runtime.ruby_home_path, ruby_path)
56
+ FileUtils.ln_s(@runtime.gem_home_path, gem_path)
57
+ end
58
+
59
+ def ruby_path
60
+ File.join(@root, 'ruby')
61
+ end
62
+
63
+ def gem_path
64
+ File.join(@root, 'gem')
65
+ end
66
+
67
+ end
68
+
69
+
70
+ module RuntimeBaseTestHelper
71
+ class RuntimeBaseStub < RubyConfig::RuntimeBase
72
+ def install;end
73
+ def archive_file_name;"filename";end
74
+ def archive_download_url;"http://download.com";end
75
+ def handle;"handle";end
76
+ def description;"description";end
77
+ end
78
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fdietz-ruby-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frederik Dietz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-29 00:00:00 -07:00
12
+ date: 2009-09-05 00:00:00 -07:00
13
13
  default_executable: ruby-config
14
14
  dependencies: []
15
15
 
@@ -22,13 +22,17 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - README.md
24
24
  files:
25
+ - README.md
26
+ - ReleaseNotes.md
27
+ - VERSION
25
28
  - bin/ruby-config
26
29
  - lib/ruby_config.rb
27
30
  - lib/ruby_config/config.rb
28
- - lib/ruby_config/file_helper.rb
31
+ - lib/ruby_config/installer.rb
29
32
  - lib/ruby_config/options_parser.rb
30
33
  - lib/ruby_config/profile_config.rb
31
34
  - lib/ruby_config/registry.rb
35
+ - lib/ruby_config/rubygems.rb
32
36
  - lib/ruby_config/runner.rb
33
37
  - lib/ruby_config/runtime_base.rb
34
38
  - lib/ruby_config/runtimes/jruby_runtime.rb
@@ -38,8 +42,8 @@ files:
38
42
  - lib/ruby_config/runtimes/ruby19_runtime.rb
39
43
  - lib/ruby_config/runtimes/ruby_enterprise_edition_runtime.rb
40
44
  - lib/ruby_config/runtimes/ruby_from_source_helper.rb
41
- - README.md
42
- has_rdoc: false
45
+ - lib/ruby_config/switcher.rb
46
+ has_rdoc: true
43
47
  homepage: http://github.com/fdietz/ruby-config
44
48
  licenses:
45
49
  post_install_message:
@@ -64,9 +68,11 @@ requirements: []
64
68
  rubyforge_project:
65
69
  rubygems_version: 1.3.5
66
70
  signing_key:
67
- specification_version: 3
71
+ specification_version: 2
68
72
  summary: Install and Switch between various Ruby Runtimes easily
69
73
  test_files:
74
+ - test/unit/installer_test.rb
70
75
  - test/unit/profile_config_test.rb
71
76
  - test/unit/registry_test.rb
72
77
  - test/unit/runtime_base_test.rb
78
+ - test/unit/switcher_test.rb
@@ -1,36 +0,0 @@
1
- module RubyConfig
2
- class FileHelper
3
-
4
- class << self
5
- def write_content_to_file(content, path)
6
- File.open(path, 'w') { |file| file.write content }
7
- end
8
-
9
- def append_content_to_file(content, path)
10
- File.open(path, 'a') { |file| file.write content }
11
- end
12
-
13
- def read_content_from_file(path)
14
- File.open(path, "r") { |file| file.read }
15
- end
16
-
17
- def store_yml(path, data)
18
- File.open(path, 'w') { |out| YAML.dump( data, out ) }
19
- end
20
-
21
- def load_yml(path)
22
- File.open(path) { |yf| YAML::load( yf ) }
23
- end
24
-
25
- def delete_file(path)
26
- File.delete(path) if File.exist?(path)
27
- end
28
-
29
- def set_symlink(target_path, symlink_path)
30
- FileUtils.ln_s(target_path, symlink_path)
31
- end
32
-
33
- end
34
-
35
- end
36
- end