gem-empty 1.1.1 → 1.1.2
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.
- checksums.yaml +4 -4
- data/lib/gem-empty/command.rb +41 -17
- data/lib/gem-empty/specification.rb +9 -5
- data/lib/gem-empty/version.rb +1 -1
- data/lib/rubygems_plugin.rb +2 -3
- data/test/gem-empty/specification_and_version_test.rb +9 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f5c71134ce63c0676f82574890f682cdda5b639
|
4
|
+
data.tar.gz: d2e74beb3bd6d83b4803ff779ed67f46de8e709c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0dc26037a708dfecb4ab473044e84334025ef219afb7d7308c26017757ba70146b909645cc66671c91da3af8790ff30ae3be7b3093f2f193cfb614a65da97e2
|
7
|
+
data.tar.gz: a72f40a5c5e9eaaf445f0e834054d56d0929fb9923f2b2f5ebb792e86f90fcb557d3116ed340d6d3f0232511f13a1b708a79d9e73708db9dcbf72c30cd915c8d
|
data/lib/gem-empty/command.rb
CHANGED
@@ -4,12 +4,19 @@ require 'rubygems/uninstaller'
|
|
4
4
|
require 'rubygems/version'
|
5
5
|
require 'fileutils'
|
6
6
|
|
7
|
+
# rubygems plugin to empty GEM_HOME
|
7
8
|
class EmptyCommand < Gem::Command
|
8
9
|
attr_reader :options
|
9
10
|
|
11
|
+
GEM_REMOVAL_ERRORS = [
|
12
|
+
Gem::DependencyRemovalException,
|
13
|
+
Gem::InstallError,
|
14
|
+
Gem::GemNotInHomeException,
|
15
|
+
Gem::FilePermissionError,
|
16
|
+
]
|
17
|
+
|
10
18
|
def initialize
|
11
|
-
super 'empty',
|
12
|
-
@default_options = { :install_dir => Gem.dir, :force => true, :executables => true }
|
19
|
+
super 'empty', description
|
13
20
|
end
|
14
21
|
|
15
22
|
def arguments # :nodoc:
|
@@ -25,34 +32,51 @@ class EmptyCommand < Gem::Command
|
|
25
32
|
end
|
26
33
|
|
27
34
|
def description # :nodoc:
|
28
|
-
|
29
|
-
Remove all gems from current 'GEM_HOME'.
|
30
|
-
DOC
|
35
|
+
"Remove all gems from current 'GEM_HOME'."
|
31
36
|
end
|
32
37
|
|
33
38
|
def execute(opts = {})
|
34
|
-
|
35
|
-
|
36
|
-
|
39
|
+
remove_gems(opts)
|
40
|
+
rescue *GEM_REMOVAL_ERRORS => exception
|
41
|
+
alert_error "#{exception.class}: #{exception.message}"
|
42
|
+
end
|
37
43
|
|
38
|
-
|
39
|
-
FileUtils.rm_rf( File.join( options[:install_dir] ,'bundler','gems' ) )
|
44
|
+
private
|
40
45
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
# A method so it's evaluated as late as possible
|
47
|
+
# giving chance to change Gem.dir
|
48
|
+
def self.default_options
|
49
|
+
{
|
50
|
+
:install_dir => Gem.dir,
|
51
|
+
:force => true,
|
52
|
+
:executables => true,
|
53
|
+
}
|
54
|
+
end
|
45
55
|
|
46
|
-
|
56
|
+
def remove_gems(opts)
|
57
|
+
@options = self.class.default_options.merge(opts)
|
58
|
+
remove_rubygems_gems
|
59
|
+
remove_bundler_gems
|
47
60
|
end
|
48
61
|
|
49
|
-
|
62
|
+
def remove_rubygems_gems
|
63
|
+
uninstaller = Gem::Uninstaller.new(nil, options)
|
64
|
+
uninstaller.remove_all(gem_dir_specs)
|
65
|
+
end
|
66
|
+
|
67
|
+
def remove_bundler_gems
|
68
|
+
FileUtils.rm_rf( File.join( gem_install_dir, 'bundler','gems' ) )
|
69
|
+
end
|
50
70
|
|
51
71
|
def gem_dir_specs
|
52
72
|
@gem_dir_specs ||=
|
53
73
|
GemEmpty::Specification.installed_gems.select do |spec|
|
54
|
-
File.exists?( File.join(
|
74
|
+
File.exists?( File.join( gem_install_dir, 'gems', spec.full_name ) )
|
55
75
|
end
|
56
76
|
end
|
57
77
|
|
78
|
+
def gem_install_dir
|
79
|
+
options[:install_dir]
|
80
|
+
end
|
81
|
+
|
58
82
|
end
|
@@ -1,17 +1,21 @@
|
|
1
1
|
module GemEmpty
|
2
|
+
# monkey patch rubygems specification to easily find gem version
|
2
3
|
module Specification
|
3
4
|
def self.installed_gems
|
4
|
-
if
|
5
|
+
if
|
6
|
+
Gem::VERSION > '1.8'
|
7
|
+
then
|
5
8
|
Gem::Specification.to_a
|
6
9
|
else
|
7
10
|
Gem.source_index.map{|name,spec| spec}
|
8
11
|
end
|
9
12
|
end
|
10
|
-
def self.
|
11
|
-
|
13
|
+
def self.find_gem_spec(name)
|
14
|
+
installed_gems.find{|spec| spec.name == name}
|
12
15
|
end
|
13
|
-
def self.version
|
14
|
-
|
16
|
+
def self.gem_loaded?(name, version)
|
17
|
+
spec = find_gem_spec(name)
|
18
|
+
spec && spec.version.to_s == version
|
15
19
|
end
|
16
20
|
end
|
17
21
|
end
|
data/lib/gem-empty/version.rb
CHANGED
data/lib/rubygems_plugin.rb
CHANGED
@@ -5,10 +5,9 @@ called_path, called_version = __FILE__.match(/^(.*\/gem-empty-([^\/]+)\/lib).*$/
|
|
5
5
|
|
6
6
|
# continue only if loaded and called versions all the same, and not shared gems disabled in bundler
|
7
7
|
if
|
8
|
-
( $:.include?(called_path) || GemEmpty::Specification.
|
8
|
+
( $:.include?(called_path) || GemEmpty::Specification.gem_loaded?("gem-empty", called_version) ) and
|
9
9
|
( !defined?(Bundler) || ( defined?(Bundler) && Bundler::SharedHelpers.in_bundle? && !Bundler.settings[:disable_shared_gems]) )
|
10
|
-
|
10
|
+
then
|
11
11
|
require 'gem-empty/command'
|
12
12
|
Gem::CommandManager.instance.register_command :empty
|
13
|
-
|
14
13
|
end
|
@@ -9,15 +9,19 @@ describe GemEmpty::Specification do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "finds specification" do
|
12
|
-
GemEmpty::Specification.
|
12
|
+
GemEmpty::Specification.find_gem_spec("gem-empty").name.must_equal("gem-empty")
|
13
13
|
end
|
14
14
|
|
15
|
-
it "
|
16
|
-
GemEmpty::Specification.
|
15
|
+
it "does not find imaginary gems" do
|
16
|
+
GemEmpty::Specification.find_gem_spec("imaginary-gem").must_equal(nil)
|
17
17
|
end
|
18
18
|
|
19
|
-
it "
|
20
|
-
GemEmpty::Specification.
|
19
|
+
it "confirms specification version" do
|
20
|
+
GemEmpty::Specification.gem_loaded?("gem-empty", GemEmpty::VERSION).must_equal true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "does not confirms specification version" do
|
24
|
+
GemEmpty::Specification.gem_loaded?("gem-empty", "0.0.0").wont_equal true
|
21
25
|
end
|
22
26
|
|
23
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem-empty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michal Papis
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-04-
|
12
|
+
date: 2015-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|