rvm 0.1.41 → 0.1.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/binscripts/rvm +1 -1
  2. data/binscripts/rvm-shell +32 -0
  3. data/binscripts/rvmsudo +1 -6
  4. data/config/db +2 -2
  5. data/config/known +2 -2
  6. data/config/md5 +6 -5
  7. data/contrib/install-system-wide +81 -0
  8. data/install +23 -24
  9. data/lib/VERSION.yml +1 -1
  10. data/lib/rvm.rb +156 -1
  11. data/lib/rvm/capistrano.rb +45 -0
  12. data/lib/rvm/environment.rb +62 -0
  13. data/lib/rvm/environment/alias.rb +69 -0
  14. data/lib/rvm/environment/cleanup.rb +54 -0
  15. data/lib/rvm/environment/configuration.rb +60 -0
  16. data/lib/rvm/environment/env.rb +52 -0
  17. data/lib/rvm/environment/gemset.rb +222 -0
  18. data/lib/rvm/environment/info.rb +13 -0
  19. data/lib/rvm/environment/list.rb +124 -0
  20. data/lib/rvm/environment/rubies.rb +50 -0
  21. data/lib/rvm/environment/sets.rb +123 -0
  22. data/lib/rvm/environment/tools.rb +41 -0
  23. data/lib/rvm/environment/utility.rb +167 -0
  24. data/lib/rvm/environment/wrapper.rb +23 -0
  25. data/lib/rvm/errors.rb +28 -0
  26. data/lib/rvm/shell.rb +21 -10
  27. data/lib/rvm/shell/abstract_wrapper.rb +145 -0
  28. data/lib/rvm/shell/result.rb +42 -0
  29. data/lib/rvm/shell/shell_wrapper.sh +10 -0
  30. data/lib/rvm/shell/single_shot_wrapper.rb +56 -0
  31. data/lib/rvm/shell/utility.rb +37 -0
  32. data/lib/rvm/version.rb +12 -8
  33. data/rvm.gemspec +27 -4
  34. data/scripts/cd +17 -32
  35. data/scripts/cli +46 -16
  36. data/scripts/completion +1 -1
  37. data/scripts/disk-usage +52 -0
  38. data/scripts/fetch +8 -2
  39. data/scripts/gemsets +15 -4
  40. data/scripts/initialize +3 -3
  41. data/scripts/install +23 -24
  42. data/scripts/list +16 -8
  43. data/scripts/log +4 -1
  44. data/scripts/man +0 -0
  45. data/scripts/manage +51 -34
  46. data/scripts/md5 +4 -5
  47. data/scripts/package +28 -6
  48. data/scripts/rubygems +2 -2
  49. data/scripts/rvm +2 -2
  50. data/scripts/rvm-install +23 -24
  51. data/scripts/selector +2 -2
  52. data/scripts/tools +34 -0
  53. data/scripts/update +23 -24
  54. data/scripts/utility +54 -12
  55. data/scripts/wrapper +21 -18
  56. metadata +29 -6
  57. data/lib/rvm/open4.rb +0 -395
  58. data/lib/rvm/rvm.rb +0 -14
@@ -0,0 +1,45 @@
1
+ # Recipes for using RVM on a server with capistrano.
2
+
3
+ unless Capistrano::Configuration.respond_to?(:instance)
4
+ abort "rvm/capistrano requires Capistrano >= 2."
5
+ end
6
+
7
+ Capistrano::Configuration.instance(true).load do
8
+
9
+ # Taken from the capistrano code.
10
+ def _cset(name, *args, &block)
11
+ unless exists?(name)
12
+ set(name, *args, &block)
13
+ end
14
+ end
15
+
16
+ set :default_shell do
17
+ shell = File.join(rvm_bin_path, "rvm-shell")
18
+ ruby = rvm_ruby_string.to_s.strip
19
+ shell = "#{shell} '#{ruby}'" unless ruby.empty?
20
+ shell
21
+ end
22
+
23
+ # Let users set the type of their rvm install.
24
+ _cset(:rvm_type, :system)
25
+
26
+ # Let users override the rvm_bin_path
27
+ _cset(:rvm_bin_path) do
28
+ case rvm_type
29
+ when :system_wide, :root, :system
30
+ "/usr/local/bin"
31
+ when :local, :user, :default
32
+ "$HOME/.rvm/bin"
33
+ end
34
+ end
35
+
36
+ # Use the default ruby.
37
+ _cset(:rvm_ruby_string, "default")
38
+
39
+ end
40
+
41
+ # E.g, to use ree and rails 3:
42
+ #
43
+ # require 'rvm/capistrano'
44
+ # set :rvm_ruby_string, "ree@rails3"
45
+ #
@@ -0,0 +1,62 @@
1
+ require 'forwardable'
2
+
3
+ module RVM
4
+ # Implements the actual wrapper around the api. For more information
5
+ # about this design, see the RVM module.
6
+ class Environment
7
+ extend Forwardable
8
+
9
+ %w(configuration utility alias list gemset rubies cleanup sets env tools info).each do |key|
10
+ require File.join("rvm", "environment", key)
11
+ end
12
+
13
+ # The default config has rvm_silence_logging so that log doesn't print anything to stdout.
14
+ merge_config! :rvm_silence_logging => 1
15
+
16
+ attr_reader :environment_name, :shell_wrapper
17
+
18
+ # Creates a new environment with the given name and optionally
19
+ # a set of extra environment variables to be set on load.
20
+ def initialize(environment_name = "default", options = {})
21
+ merge_config! options
22
+ @environment_name = environment_name
23
+ @shell_wrapper = Shell.default_wrapper.new
24
+ @shell_wrapper.setup do |s|
25
+ source_rvm_environment
26
+ use_rvm_environment
27
+ end
28
+ end
29
+
30
+ def inspect
31
+ "#<#{self.class.name} environment_name=#{@environment_name.inspect}>"
32
+ end
33
+
34
+ # Returns the expanded name, using the same method as used by the rvm command line.
35
+ def expanded_name
36
+ @expanded_name ||= tools_identifier.to_s
37
+ end
38
+
39
+ # Actually define methods to interact with the shell wrapper.
40
+ def_delegators :@shell_wrapper, :run, :run_silently, :run_command_without_output,
41
+ :run_command, :[], :escape_argument
42
+
43
+ protected
44
+
45
+ # Automatically load rvm config from the multiple sources.
46
+ def source_rvm_environment
47
+ rvm_path = config_value_for(:rvm_path, File.expand_path("~/.rvm"), false)
48
+ actual_config = defined_config.merge('rvm_path' => rvm_path)
49
+ config = []
50
+ actual_config.each_pair do |k, v|
51
+ config << "#{k}=#{escape_argument(v.to_s)}"
52
+ end
53
+ run_silently :export, config.join(" ")
54
+ run_silently :source, File.join(rvm_path, "scripts", "rvm")
55
+ end
56
+
57
+ def use_rvm_environment
58
+ rvm :use, @environment_name, :silent => true
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,69 @@
1
+ module RVM
2
+ class Environment
3
+
4
+ # Returns a hash of aliases.
5
+ def alias_list
6
+ lines = normalize_array(rvm(:alias, :list).stdout)
7
+ lines.inject({}) do |acc, current|
8
+ alias_name, ruby_string = current.to_s.split(" => ")
9
+ unless alias_name.empty? || ruby_string.empty?
10
+ acc[alias_name] = ruby_string
11
+ end
12
+ acc
13
+ end
14
+ end
15
+
16
+ # Shows the full ruby string that a given alias points to.
17
+ def alias_show(name)
18
+ normalize rvm(:alias, :show, name.to_s).stdout
19
+ end
20
+
21
+ # Deletes an alias and returns the exit status.
22
+ def alias_delete(name)
23
+ rvm(:alias, :delete, name.to_s).successful?
24
+ end
25
+
26
+ # Creates an alias with the given name.
27
+ def alias_create(name, ruby_string)
28
+ rvm(:alias, :create, name.to_s, ruby_string.to_s).successful?
29
+ end
30
+
31
+ # Returns an aliases proxy which can be used in a more Ruby-like manner.
32
+ def aliases
33
+ @aliases ||= AliasWrapper.new(self)
34
+ end
35
+
36
+ # Provides a Ruby-like wrapper to the alias functionality.
37
+ class AliasWrapper
38
+
39
+ def initialize(parent)
40
+ @parent = parent
41
+ end
42
+
43
+ # Shows the value of a given alias.
44
+ def show(name)
45
+ @parent.alias_show name
46
+ end
47
+ alias [] show
48
+
49
+ # Deletes the given alias.
50
+ def delete(name)
51
+ @parent.alias_delete name
52
+ end
53
+
54
+ # Creates an alias with a given name and ruby string.
55
+ def create(name, ruby_string)
56
+ @parent.alias_create name, ruby_string
57
+ end
58
+ alias []= create
59
+
60
+ # Returns a hash of all aliases.
61
+ def list
62
+ @parent.alias_list
63
+ end
64
+ alias all list
65
+
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,54 @@
1
+ module RVM
2
+ class Environment
3
+
4
+ # Batch define common operations.
5
+ %w(all archives repos sources logs).each do |cleanup_type|
6
+ define_method(:"cleanup_#{cleanup_type}") do
7
+ rvm(:cleanup, cleanup_type).successful?
8
+ end
9
+ end
10
+
11
+ # Returns the ruby-like interface defined by CleanupWrapper
12
+ def cleanup
13
+ @cleanup_wrapper ||= CleanupWrapper.new(self)
14
+ end
15
+
16
+ # Implements a Ruby-like interface to cleanup, making it nicer to deal with.
17
+ class CleanupWrapper
18
+
19
+ def initialize(parent)
20
+ @parent = parent
21
+ end
22
+
23
+ # Cleans up archives, repos, sources and logs
24
+ def all
25
+ @parent.cleanup_all
26
+ end
27
+ alias everything all
28
+
29
+ # Cleans up everything in the archives folder
30
+ def archives
31
+ @parent.cleanup_archives
32
+ end
33
+
34
+ # Cleans up everything in the repos path
35
+ def repos
36
+ @parent.cleanup_repos
37
+ end
38
+ alias repositories repos
39
+
40
+ # Cleans up everything in the source folder
41
+ def sources
42
+ @parent.cleanup_sources
43
+ end
44
+ alias src sources
45
+
46
+ # Cleans up all of the logs
47
+ def logs
48
+ @parent.cleanup_logs
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,60 @@
1
+ module RVM
2
+ class Environment
3
+
4
+ # Define the config accessor, which basically uses config_value_for and
5
+ # the linke to set the env variable.
6
+ def self.define_config_accessor(*args)
7
+ singleton = (class << self; self; end)
8
+ args.each do |arg|
9
+ singleton.send(:define_method, arg) { RVM::Environment.config_value_for(arg) }
10
+ singleton.send(:define_method, :"#{arg}=") { |v| RVM::Environment.merge_config! arg => v }
11
+ end
12
+ end
13
+
14
+ define_config_accessor :rvm_path, :rvm_config_path, :rvm_bin_path
15
+
16
+ # Mixin for a set of configs.
17
+ module ConfigMixin
18
+
19
+ # Returns the current config for this scope
20
+ def config
21
+ @config ||= {}
22
+ end
23
+
24
+ # Merge a set of items into the config.
25
+ def merge_config!(r)
26
+ r.each_pair { |k, v| config[k.to_s] = v }
27
+ end
28
+
29
+ # Reset this local config to be empty.
30
+ def clear_config!
31
+ @config = {}
32
+ end
33
+ end
34
+
35
+ include ConfigMixin
36
+ extend ConfigMixin
37
+
38
+ # Gets the default option or the current
39
+ # environment variable for a given env var.
40
+ def self.config_value_for(value)
41
+ value = value.to_s
42
+ config[value] || ENV[value]
43
+ end
44
+
45
+ # Returns the value for a configuration option (mapping to an
46
+ # environment variable). If check_live is true (which it is
47
+ # by default), it will also check the environment for a value.
48
+ def config_value_for(key, default = nil, check_live = true)
49
+ key = key.to_s
50
+ value = check_live ? self[key.to_s] : nil
51
+ value || config[key] || self.class.config_value_for(key) || default
52
+ end
53
+
54
+ # Returns a hash of all of the user defined configuration.
55
+ def defined_config
56
+ self.class.config.merge(self.config)
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,52 @@
1
+ module RVM
2
+ class Environment
3
+
4
+ # Returns the contents of the env file.
5
+ def env_contents
6
+ rvm(:env).stdout
7
+ end
8
+
9
+ # Returns the path to the env file
10
+ def env_path
11
+ rvm(:env, :path => true).stdout.strip
12
+ end
13
+
14
+ # Returns a ruby-like wrapper for the env functions
15
+ def env
16
+ @env_wrapper ||= EnvWrapper.new(self)
17
+ end
18
+
19
+ # Returns the path for the given command
20
+ def path_for(command)
21
+ run(:command, "-v", command).stdout.strip
22
+ end
23
+ alias which path_for
24
+
25
+ # Simple ruby like wrapper for envs.
26
+ class EnvWrapper
27
+
28
+ def initialize(parent)
29
+ @parent = parent
30
+ end
31
+
32
+ # Contents of the env file.
33
+ def contents
34
+ @parent.env_contents
35
+ end
36
+ alias read contents
37
+ alias to_s contents
38
+
39
+ # The path of the env file.
40
+ def path
41
+ @parent.env_path
42
+ end
43
+
44
+ # Opens a file on the env file.
45
+ def to_file
46
+ File.open(path)
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,222 @@
1
+ module RVM
2
+ class Environment
3
+
4
+ # Loads a gemset into the current environment.
5
+ # If an argument is given, it will load it from
6
+ # file_prefix.gems
7
+ def gemset_import(file_prefix = nil)
8
+ args = [file_prefix].compact
9
+ rvm(:gemset, :import, *args).successful?
10
+ end
11
+ alias gemset_load gemset_import
12
+
13
+ # Exports a gemset.
14
+ def gemset_export(gemset_or_file = nil)
15
+ args = [gemset_or_file].compact
16
+ rvm(:gemset, :export, *args).successful?
17
+ end
18
+ alias gemset_dump gemset_export
19
+
20
+ def gemset_list
21
+ normalize_array rvm(:gemset, :list).stdout
22
+ end
23
+
24
+ # Creates a new gemset with the given name.
25
+ def gemset_create(*names)
26
+ names = names.flatten
27
+ rvm(:gemset, :create, *names).successful?
28
+ end
29
+
30
+ # Copies the gems between two different gemsets.
31
+ def gemset_copy(from, to)
32
+ rvm(:gemset, :copy, from, to).successful?
33
+ end
34
+
35
+ # Deletes the gemset with a given name.
36
+ def gemset_delete(name)
37
+ run("echo 'yes' | rvm", :gemset, :delete, name.to_s).successful?
38
+ end
39
+
40
+ # Removes all gem-related stuff from the current gemset.
41
+ def gemset_empty
42
+ run("echo 'yes' | rvm", :gemset, :empty).successful?
43
+ end
44
+
45
+ # Resets the current gemset to a pristine state.
46
+ def gemset_pristine
47
+ rvm(:gemset, :pristine).successful?
48
+ end
49
+
50
+ # Updates all gems in the current gemset.
51
+ def gemset_update
52
+ rvm(@environment_name, :gemset, :update).successful?
53
+ end
54
+
55
+ # Prunes the gem cache for the current ruby.
56
+ def gemset_prune
57
+ rvm(:gemset, :prune).successful?
58
+ end
59
+
60
+ # Initializes gemsets for a given ruby.
61
+ def gemset_intial
62
+ rvm(:gemset, :initial).successful?
63
+ end
64
+
65
+ # Enable or disable the rvm gem global cache.
66
+ def gemset_globalcache(enable = true)
67
+ case enable
68
+ when "enabled", :enabled
69
+ run(:__rvm_using_gemset_globalcache).successful?
70
+ when true, "enable", :enable
71
+ rvm(:gemset, :globalcache, :enable).successful?
72
+ when false, "disable", :disable
73
+ rvm(:gemset, :globalcache, :disable).successful?
74
+ else
75
+ false
76
+ end
77
+ end
78
+
79
+ # Changes the current environments gemset. If :replace_env is passed
80
+ # and the ruby is compatible, it will attempt to replace the current
81
+ # processes gem home and path with the one requested.
82
+ def gemset_use(gemset, options = {})
83
+ replace_env = options.delete(:replace_env)
84
+ result = rvm(:gemset, :use, gemset, options)
85
+ if result.successful?
86
+ gemset_name = result[:rvm_gemset_name]
87
+ @environment_name = self.class.environment_with_gemset(@environment_name, gemset_name)
88
+ @expanded_name = nil
89
+ self.class.reset_current!
90
+ use_env_from_result! result if replace_env
91
+ true
92
+ end
93
+ end
94
+
95
+ # Like gemset_use, but replaces the env by default.
96
+ def gemset_use!(name, options = {})
97
+ gemset_use name, {:replace_env => true}.merge(options)
98
+ end
99
+
100
+ %w(gemdir gempath gemhome home path version name string dir).each do |action|
101
+ define_method(:"gemset_#{action}") do
102
+ normalize rvm(:gemset, action).stdout
103
+ end
104
+ end
105
+
106
+ # Returns the Ruby-like wrapper for gemset operations.
107
+ def gemset
108
+ @gemset_wrapper ||= GemsetWrapper.new(self)
109
+ end
110
+
111
+ # Wraps the gemset functionality.
112
+ class GemsetWrapper
113
+ extend Forwardable
114
+
115
+ def initialize(parent)
116
+ @parent = parent
117
+ end
118
+
119
+ # Import a gemset file.
120
+ def import(prefix)
121
+ @parent.gemset_export prefix.to_s.gsub(/\.gems$/, '')
122
+ end
123
+ alias load import
124
+
125
+ # Export a given gemset or, if the name ends with .gems, the current gemset.
126
+ def export(path_or_name)
127
+ @parent.gemset_export path_or_name.to_s
128
+ end
129
+ alias dump export
130
+ alias save export
131
+
132
+ # Returns a list of all gemsets belonging to the current ruby.
133
+ def list
134
+ @parent.gemset_list
135
+ end
136
+ alias all list
137
+
138
+ # Creates gemsets with the given names.
139
+ def create(*names)
140
+ @parent.gemset_create(*names.flatten)
141
+ end
142
+
143
+ # Delete a given gemset.
144
+ def delete(name)
145
+ @parent.gemset_delete(name)
146
+ end
147
+
148
+ # Empty the current gemset.
149
+ def empty
150
+ @parent.gemset_empty
151
+ end
152
+
153
+ # Restores the current gemset to a pristine state.
154
+ def pristine
155
+ @parent.gemset_pristine
156
+ end
157
+
158
+ # Updates all gems in the current gemset.
159
+ def update
160
+ @parent.gemset_update
161
+ end
162
+
163
+ # Prune the current gemset.
164
+ def prune
165
+ @parent.gemset_prune
166
+ end
167
+
168
+ # Use a given gemset in this environment
169
+ def use(name)
170
+ @parent.gemset_use(name)
171
+ end
172
+
173
+ # Use the given gemset, replacing the current
174
+ # gem environment if possible.
175
+ def use!(name)
176
+ @parent.gemset_use(name, :replace_env => true)
177
+ end
178
+
179
+ # Shortcut to deal with the gemset global cache.
180
+ def globalcache
181
+ @globalcache ||= GlobalCacheHelper.new(@parent)
182
+ end
183
+
184
+ # Copy gems from one gemset to another.
185
+ def copy(from, to)
186
+ @parent.gemset_copy(from, to)
187
+ end
188
+
189
+ %w(gemdir gempath gemhome home path version name string dir).each do |action|
190
+ define_method(action) do
191
+ @parent.send(:"gemset_#{action}")
192
+ end
193
+ end
194
+
195
+ # A Ruby-like wrapper to manipulate the rvm gem global cache.
196
+ class GlobalCacheHelper
197
+
198
+ def initialize(parent)
199
+ @parent = parent
200
+ end
201
+
202
+ # Enable the globalcache
203
+ def enable!
204
+ @parent.gemset_globalcache :enable
205
+ end
206
+
207
+ # Disable the globalcache
208
+ def disable!
209
+ @parent.gemset_globalcache :disable
210
+ end
211
+
212
+ # Returns whether or not the globalcache is enabled.
213
+ def enabled?
214
+ @parent.gemset_globalcache :enabled
215
+ end
216
+
217
+ end
218
+
219
+ end
220
+
221
+ end
222
+ end