fdietz-ruby-config 0.2.0 → 0.3.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.
@@ -5,7 +5,15 @@ module RubyConfig
5
5
  def write_content_to_file(content, path)
6
6
  File.open(path, 'w') { |file| file.write content }
7
7
  end
8
+
9
+ def append_content_to_file(content, path)
10
+ File.open(path, 'a') { |file| file.write content }
11
+ end
8
12
 
13
+ def read_content_from_file(path)
14
+ File.open(path, "r") { |file| file.read }
15
+ end
16
+
9
17
  def store_yml(path, data)
10
18
  File.open(path, 'w') { |out| YAML.dump( data, out ) }
11
19
  end
@@ -17,7 +17,9 @@ module RubyConfig
17
17
  @options.use = false
18
18
  @options.runtime = nil
19
19
  @options.install = false
20
+ @options.uninstall = false
20
21
  @options.help = false
22
+ @options.setup = false
21
23
 
22
24
  @optparse = OptionParser.new do |opts|
23
25
  opts.banner = "Usage: ruby-config [options]"
@@ -47,9 +49,13 @@ module RubyConfig
47
49
  @options.runtime = runtime
48
50
  abort("No Runtime specified") unless runtime
49
51
  end
52
+
53
+ opts.on('--setup', 'Setup your bash script') do
54
+ @options.setup = true
55
+ end
50
56
 
51
57
  opts.on('-v', '--version', 'Display version' ) do
52
- puts "ruby-config version: #{RubyConfig.VERSION}"
58
+ puts "ruby-config version: #{RubyConfig.version}"
53
59
  exit
54
60
  end
55
61
 
@@ -0,0 +1,65 @@
1
+ # Not used currently
2
+ module RubyConfig
3
+ class ProfileConfig
4
+
5
+ def initialize(bash_profile_path)
6
+ @bash_profile_path = bash_profile_path
7
+ end
8
+
9
+ def change
10
+ RubyConfig::FileHelper.append_content_to_file(content_with_header, @bash_profile_path)
11
+ end
12
+
13
+ def exists?
14
+ RubyConfig::FileHelper.read_content_from_file(@bash_profile_path).include?(content)
15
+ end
16
+
17
+ def content_with_header
18
+ str = header
19
+ str << content
20
+ str
21
+ end
22
+
23
+ def content
24
+ str = ""
25
+ [ruby_home, gem_home, gem_path, path].each do |line|
26
+ str << export_line(line)
27
+ end
28
+ str
29
+ end
30
+
31
+ private
32
+
33
+ def header
34
+ "# ruby-config v#{RubyConfig.version}"
35
+ end
36
+
37
+ def ruby_home
38
+ "RUBY_HOME=#{home}/#{ruby_config}/ruby"
39
+ end
40
+
41
+ def gem_home
42
+ "GEM_HOME=#{home}/#{ruby_config}/gem"
43
+ end
44
+
45
+ def gem_path
46
+ "GEM_PATH=#{home}/#{ruby_config}/gem"
47
+ end
48
+
49
+ def path
50
+ "PATH=$RUBY_HOME/bin:$GEM_HOME/bin:$PATH"
51
+ end
52
+
53
+ def home
54
+ "$HOME"
55
+ end
56
+
57
+ def ruby_config
58
+ ".ruby-config"
59
+ end
60
+
61
+ def export_line(str)
62
+ "export #{str}\n"
63
+ end
64
+ end
65
+ end
@@ -1,3 +1,6 @@
1
+ require 'ruby_config/config'
2
+ require 'ruby_config/file_helper'
3
+
1
4
  module RubyConfig
2
5
 
3
6
  class Registry
@@ -10,7 +13,6 @@ module RubyConfig
10
13
  @tmp_path = File.join(ruby_config_path, "tmp")
11
14
 
12
15
  @config = RubyConfig::Config.new(@ruby_config_path)
13
- @environment_config = RubyConfig::EnvironmentConfig.new(@ruby_config_path)
14
16
 
15
17
  @list = []
16
18
  ensure_config_directory_exists
@@ -93,17 +95,6 @@ module RubyConfig
93
95
  FileUtils.mkdir_p(@runtime_install_path)
94
96
  end
95
97
 
96
- # bash_alias required by jruby nailgun
97
- # def update_current_environment_config(ruby_home, gem_home, bash_alias = {})
98
- # set_bash_var = {'GEM_HOME' => gem_home, 'RUBY_HOME' => ruby_home}
99
- # prepend_bash_var = {'PATH' => "#{ruby_home}/bin" }
100
- #
101
- # @environment_config.set_bash_var = set_bash_var
102
- # @environment_config.prepend_bash_var = prepend_bash_var
103
- # @environment_config.bash_alias = bash_alias
104
- # @environment_config.save
105
- # end
106
-
107
98
  end
108
99
 
109
100
  end
@@ -1,3 +1,9 @@
1
+ require 'ruby_config/runtime_base'
2
+ require 'ruby_config/options_parser'
3
+ require 'ruby_config/profile_config'
4
+
5
+ Dir.glob(File.join(File.dirname(__FILE__), 'runtimes/*.rb')).each {|f| require f }
6
+
1
7
  module RubyConfig
2
8
 
3
9
  class Runner
@@ -22,11 +28,13 @@ module RubyConfig
22
28
  elsif options.install
23
29
  install_runtime(options.runtime)
24
30
  elsif options.uninstall
25
- # TODO
31
+ uninstall(options.runtime)
26
32
  elsif options.use
27
33
  use_runtime(options.runtime)
28
34
  elsif options.help
29
35
  help(options_parser)
36
+ elsif options.setup
37
+ setup
30
38
  end
31
39
  rescue OptionParser::ParseError => e
32
40
  puts e
@@ -36,6 +44,49 @@ module RubyConfig
36
44
 
37
45
  private
38
46
 
47
+ def setup
48
+ config = RubyConfig::ProfileConfig.new(bash_profile_path)
49
+
50
+ if config.exists?
51
+ puts "Found existing profile configuration. You are all set!"
52
+ else
53
+ puts "Ruby-Config will add the following lines to your environment:"
54
+ puts "#{bash_profile_path}:"
55
+ puts config.content
56
+ puts
57
+
58
+ if agree("Append configuration to your profile? [y/n] ", true)
59
+ config.change
60
+ puts
61
+ puts "Done! To apply changes execute the following command:"
62
+ puts " source #{bash_profile_path}"
63
+ end
64
+ end
65
+ end
66
+
67
+ def bash_profile_path
68
+ File.join(ENV['HOME'], '.bash_profile')
69
+ end
70
+
71
+ def uninstall(handle)
72
+ unless @registry.exist?(handle)
73
+ puts "Unknown ruby runtime: #{handle}."
74
+ return
75
+ end
76
+
77
+ if @registry.default?(handle)
78
+ puts "Can't delete currently selected runtime."
79
+ return
80
+ end
81
+
82
+ runtime = @registry.get(handle)
83
+
84
+ if agree("Really want to delete: #{runtime.description}? [y/n] ", true)
85
+ runtime.delete
86
+ puts "Done!"
87
+ end
88
+ end
89
+
39
90
  def load_available_runtimes
40
91
  list = []
41
92
  list << RubyConfig::Runtimes::LeopardRuntime
@@ -94,7 +145,7 @@ module RubyConfig
94
145
  def print_info_header
95
146
  puts "ruby-config (http://github/fdietz/ruby-config)"
96
147
  puts "Author: Frederik Dietz <fdietz@gmail.com>"
97
- puts "Version: #{RubyConfig::VERSION}"
148
+ puts "Version: #{RubyConfig.version}"
98
149
  puts
99
150
  end
100
151
 
@@ -152,14 +203,4 @@ module RubyConfig
152
203
  end
153
204
 
154
205
  end
155
- end
156
-
157
- #RubyConfig::Runner.new.run
158
-
159
-
160
- # require 'fileutils'
161
- # if ARGV.include?('--dry-run')
162
- # include FileUtils::DryRun
163
- # else
164
- # include FileUtils::Verbose
165
- # end
206
+ end
@@ -101,6 +101,10 @@ module RubyConfig
101
101
  Pathname.new(File.join(ruby_bin_path, 'ruby')).exist?
102
102
  end
103
103
 
104
+ def delete
105
+ FileUtils.remove_entry_secure(@install_path)
106
+ end
107
+
104
108
  protected
105
109
 
106
110
  def install_rubygems
data/lib/ruby_config.rb CHANGED
@@ -1,15 +1,20 @@
1
- #puts Dir.glob(File.join(File.dirname(__FILE__), 'ruby_config/**/*.rb'))
2
- Dir.glob(File.join(File.dirname(__FILE__), 'ruby_config/**/*.rb')).each {|f| require f }
3
-
4
- module RubyConfig
5
- VERSION = '1.0.0'
6
- end
7
-
1
+ require 'rubygems'
8
2
  require 'fileutils'
9
3
  require 'open-uri'
10
4
  require 'tempfile'
11
5
  require 'pathname'
12
6
  require 'ostruct'
13
7
  require 'optparse'
14
- require "yaml"
8
+ require 'yaml'
9
+ require 'highline/import'
10
+
11
+ require 'ruby_config/runner'
12
+ require 'ruby_config/registry'
13
+ require 'ruby_config/file_helper'
14
+
15
+ module RubyConfig
16
+ def self.version
17
+ RubyConfig::FileHelper.read_content_from_file(File.join(File.dirname(__FILE__), '..', 'VERSION'))
18
+ end
19
+ end
15
20
 
@@ -22,7 +22,6 @@ class RuntimeBaseDoInstallTest < Test::Unit::TestCase
22
22
  test "should create directory structure" do
23
23
  r = RuntimeBaseTestHelper::RuntimeBaseStub.new(File.join(@root, "install"), File.join(@root, "tmp"))
24
24
  r.stubs(:download_file_unless_exists)
25
- r.stubs(:already_installed?).returns(true)
26
25
  r.do_install
27
26
 
28
27
  assert File.exist?(r.install_path)
@@ -33,23 +32,12 @@ class RuntimeBaseDoInstallTest < Test::Unit::TestCase
33
32
  test "should install runtime and cleanup tmp unless installed already" do
34
33
  r = RuntimeBaseTestHelper::RuntimeBaseStub.new(File.join(@root, "install"), File.join(@root, "tmp"))
35
34
  r.stubs(:download_file_unless_exists)
36
- r.stubs(:already_installed?).returns(false)
37
35
 
38
36
  r.expects(:install).once
39
37
  r.expects(:cleanup_tmp_dir).once
40
38
  r.do_install
41
39
  end
42
40
 
43
- test "should NOT install runtime if installed already" do
44
- r = RuntimeBaseTestHelper::RuntimeBaseStub.new(File.join(@root, "install"), File.join(@root, "tmp"))
45
- r.stubs(:download_file_unless_exists)
46
- r.stubs(:already_installed?).returns(true)
47
-
48
- r.expects(:install).never
49
- r.expects(:cleanup_tmp_dir).never
50
- r.do_install
51
- end
52
-
53
41
  end
54
42
 
55
43
  class RuntimeBaseDownloadFileUnlessExists < Test::Unit::TestCase
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.2.0
4
+ version: 0.3.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-24 00:00:00 -07:00
12
+ date: 2009-08-29 00:00:00 -07:00
13
13
  default_executable: ruby-config
14
14
  dependencies: []
15
15
 
@@ -25,9 +25,9 @@ files:
25
25
  - bin/ruby-config
26
26
  - lib/ruby_config.rb
27
27
  - lib/ruby_config/config.rb
28
- - lib/ruby_config/environment_config.rb
29
28
  - lib/ruby_config/file_helper.rb
30
29
  - lib/ruby_config/options_parser.rb
30
+ - lib/ruby_config/profile_config.rb
31
31
  - lib/ruby_config/registry.rb
32
32
  - lib/ruby_config/runner.rb
33
33
  - lib/ruby_config/runtime_base.rb
@@ -41,7 +41,6 @@ files:
41
41
  - README.md
42
42
  has_rdoc: false
43
43
  homepage: http://github.com/fdietz/ruby-config
44
- licenses:
45
44
  post_install_message:
46
45
  rdoc_options:
47
46
  - --charset=UTF-8
@@ -62,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
61
  requirements: []
63
62
 
64
63
  rubyforge_project:
65
- rubygems_version: 1.3.5
64
+ rubygems_version: 1.2.0
66
65
  signing_key:
67
66
  specification_version: 3
68
67
  summary: Install and Switch between various Ruby Runtimes easily
@@ -1,43 +0,0 @@
1
- # Not used currently
2
- module RubyConfig
3
- class EnvironmentConfig
4
-
5
- attr_writer :set_bash_var, :prepend_bash_var, :append_bash_var, :bash_alias
6
-
7
- def initialize(path)
8
- @config_file = File.join(path, "current_env_config")
9
- end
10
-
11
- def save
12
- configuration = create_configuration(@set_bash_var, @prepend_bash_var, @append_bash_var, @bash_alias)
13
- RubyConfig::FileHelper.write_content_to_file(configuration, @config_file)
14
- end
15
-
16
- private
17
-
18
- def create_configuration(set_bash_var = {}, prepend_bash_var = {}, append_bash_var = {}, bash_alias = {})
19
- configuration = ""
20
- prepend_bash_var.each { |key,value| configuration << prepend_to_bash_environment_var(key, value) + "\n" }
21
- set_bash_var.each { |key,value| configuration << set_bash_environment_var(key, value) + "\n" }
22
- bash_alias.each { |key, value| configuration << set_bash_alias(key, value) + "\n" }
23
- configuration
24
- end
25
-
26
- def prepend_to_bash_environment_var(var, path)
27
- "export #{var}=#{path}:$#{var}"
28
- end
29
-
30
- def append_to_bash_environment_var(var, path)
31
- "export #{var}=$#{var}:#{path}"
32
- end
33
-
34
- def set_bash_environment_var(var, path)
35
- "export #{var}=#{path}"
36
- end
37
-
38
- def set_bash_alias(var, script)
39
- "alias #{var}=\"#{script}\""
40
- end
41
-
42
- end
43
- end