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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 349a468f9781f3f46f9c6f00443a19f910af56a0
4
- data.tar.gz: 8d643f44c77a4c93f7d98aa333f580126a77b32b
3
+ metadata.gz: 7f5c71134ce63c0676f82574890f682cdda5b639
4
+ data.tar.gz: d2e74beb3bd6d83b4803ff779ed67f46de8e709c
5
5
  SHA512:
6
- metadata.gz: 86cb35d631293e0b1ae0bab92ed98811f2e88947512e64a4212f66358c770093860f6919303fdb0f71fb008261461c33643b76fbd55e91b2e68f5bdc8f87aad2
7
- data.tar.gz: 83a4ee04e44e69b7bed6a4842b8f2e991b7f3b72ee79bae0122e5ccfc51c37a2e55185fb69f64545162bea9d48d4ef7312b08bb313ef01441ad7d601ad10f713
6
+ metadata.gz: b0dc26037a708dfecb4ab473044e84334025ef219afb7d7308c26017757ba70146b909645cc66671c91da3af8790ff30ae3be7b3093f2f193cfb614a65da97e2
7
+ data.tar.gz: a72f40a5c5e9eaaf445f0e834054d56d0929fb9923f2b2f5ebb792e86f90fcb557d3116ed340d6d3f0232511f13a1b708a79d9e73708db9dcbf72c30cd915c8d
@@ -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', 'Remove all gems from current GEM_HOME.'
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
- <<-DOC
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
- @options = @default_options.merge(opts)
35
- uninstaller = Gem::Uninstaller.new(nil, options)
36
- uninstaller.remove_all(gem_dir_specs)
39
+ remove_gems(opts)
40
+ rescue *GEM_REMOVAL_ERRORS => exception
41
+ alert_error "#{exception.class}: #{exception.message}"
42
+ end
37
43
 
38
- # Remove any Git gems installed via bundler
39
- FileUtils.rm_rf( File.join( options[:install_dir] ,'bundler','gems' ) )
44
+ private
40
45
 
41
- rescue Gem::DependencyRemovalException,
42
- Gem::InstallError,
43
- Gem::GemNotInHomeException,
44
- Gem::FilePermissionError => e
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
- alert_error "#{e.class}: #{e.message}"
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
- private
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( options[:install_dir], 'gems', spec.full_name ) )
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 Gem::VERSION > '1.8' then
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.find(name = "gem-empty")
11
- @gem_empty_spec ||= installed_gems.find{|spec| spec.name == name}
13
+ def self.find_gem_spec(name)
14
+ installed_gems.find{|spec| spec.name == name}
12
15
  end
13
- def self.version
14
- find ? find.version.to_s : nil
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
@@ -1,3 +1,3 @@
1
1
  module GemEmpty
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -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.version == called_version ) and
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.find("gem-empty").name.must_equal("gem-empty")
12
+ GemEmpty::Specification.find_gem_spec("gem-empty").name.must_equal("gem-empty")
13
13
  end
14
14
 
15
- it "gets specification version" do
16
- GemEmpty::Specification.version.must_equal(GemEmpty::VERSION)
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 "does not find imaginary gems" do
20
- GemEmpty::Specification.find("imaginary-gem").must_equal(nil)
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.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-23 00:00:00.000000000 Z
12
+ date: 2015-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake