gem-depclean 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.2.5
@@ -1,48 +1,14 @@
1
1
  require 'rubygems/command'
2
- require 'rubygems/uninstaller'
3
- require 'set'
2
+
3
+ require File.expand_path('world_command', File.dirname(__FILE__))
4
4
 
5
5
  class Gem::Commands::DepcleanCommand < Gem::Command
6
6
  def initialize
7
7
  super 'depclean', 'Uninstall all unnecessary gems'
8
8
  end
9
9
 
10
- def world
11
- Gem::CommandManager.instance['world']
12
- end
13
-
14
10
  def execute
15
- gems = world.world_gems.inject(Set.new) {|acc, gem|
16
- acc + collect_dependencies(gem)
17
- }
18
-
19
- targets = (Gem.source_index.map(&:last) - gems.to_a).sort_by(&:name)
20
-
21
- if targets.empty?
22
- say 'Your world is already clean.'
23
- return
24
- end
25
-
26
- targets.each do |t|
27
- say "#{t.name} (#{t.version})"
28
- end
29
-
30
- return unless ask_yes_no 'Would you like to uninstall these gems?'
31
-
32
- targets.each do |gem|
33
- Gem::Uninstaller.new(gem.name, :version => gem.version, :user_install => true, :ignore => true).uninstall
34
- end
35
- end
36
-
37
- def collect_dependencies(gem, acc = Set.new)
38
- acc << gem
39
-
40
- gem.dependencies.map {|dep|
41
- Gem.source_index.find_name(dep.name, dep.version_requirements).sort_by(&:version).last
42
- }.compact.reject {|s| acc.include?(s) }.each do |dep|
43
- collect_dependencies(dep, acc)
44
- end
45
-
46
- acc
11
+ alert_warning "'gem depclean' is obsolete. Use 'gem world --depclean' instead."
12
+ Gem::Commands::WorldCommand.new.depclean
47
13
  end
48
14
  end
@@ -1,5 +1,7 @@
1
1
  require 'rubygems/command'
2
2
  require 'rubygems/requirement'
3
+ require 'rubygems/uninstaller'
4
+ require 'set'
3
5
  require 'yaml'
4
6
 
5
7
  class Gem::Commands::WorldCommand < Gem::Command
@@ -7,21 +9,17 @@ class Gem::Commands::WorldCommand < Gem::Command
7
9
  File.join(Gem.user_dir, 'world')
8
10
  end
9
11
 
10
- def world_gems
11
- YAML.load_file(world_path).inject([]) {|acc, (name, versions)|
12
- acc + versions.map {|v|
13
- Gem.source_index.find_name(name, v).sort_by(&:version).last
14
- }.compact
15
- }
16
- end
17
-
18
12
  def initialize
19
- super 'world', 'Display gems that in your world'
13
+ super 'world', 'Manage gems that in your world'
20
14
 
21
15
  add_option '--init' do |v, opts|
22
16
  opts[:init] = v
23
17
  end
24
18
 
19
+ add_option '--depclean' do |v, opts|
20
+ opts[:depclean] = v
21
+ end
22
+
25
23
  add_option '-e', '--edit' do |v, opts|
26
24
  opts[:edit] = v
27
25
  end
@@ -29,7 +27,9 @@ class Gem::Commands::WorldCommand < Gem::Command
29
27
 
30
28
  def execute
31
29
  if options[:init]
32
- generate
30
+ init
31
+ elsif options[:depclean]
32
+ depclean
33
33
  elsif options[:edit]
34
34
  edit
35
35
  else
@@ -37,7 +37,7 @@ class Gem::Commands::WorldCommand < Gem::Command
37
37
  end
38
38
  end
39
39
 
40
- def generate
40
+ def init
41
41
  if File.exist?(world_path)
42
42
  terminate_interaction unless ask_yes_no "'#{world_path}' is already exists. overwrite?"
43
43
  end
@@ -56,6 +56,31 @@ class Gem::Commands::WorldCommand < Gem::Command
56
56
  say "'#{world_path}' was successfully initialized."
57
57
  end
58
58
 
59
+ def depclean
60
+ terminate_if_world_is_missing
61
+
62
+ gems = world_gems.inject(Set.new) {|acc, gem|
63
+ acc + collect_dependencies(gem)
64
+ }
65
+
66
+ targets = (Gem.source_index.map(&:last) - gems.to_a).sort_by(&:name)
67
+
68
+ if targets.empty?
69
+ say 'Your world is already clean.'
70
+ terminate_interaction
71
+ end
72
+
73
+ targets.each do |t|
74
+ say "#{t.name} (#{t.version})"
75
+ end
76
+
77
+ terminate_interaction unless ask_yes_no 'Would you like to uninstall these gems?'
78
+
79
+ targets.each do |gem|
80
+ Gem::Uninstaller.new(gem.name, :version => gem.version, :user_install => true, :ignore => true).uninstall
81
+ end
82
+ end
83
+
59
84
  def edit
60
85
  terminate_if_world_is_missing
61
86
 
@@ -97,6 +122,26 @@ class Gem::Commands::WorldCommand < Gem::Command
97
122
  terminate_interaction
98
123
  end
99
124
  end
125
+
126
+ def world_gems
127
+ YAML.load_file(world_path).inject([]) {|acc, (name, versions)|
128
+ acc + versions.map {|v|
129
+ Gem.source_index.find_name(name, v).sort_by(&:version).last
130
+ }.compact
131
+ }
132
+ end
133
+
134
+ def collect_dependencies(gem, acc = Set.new)
135
+ acc << gem
136
+
137
+ gem.dependencies.map {|dep|
138
+ Gem.source_index.find_name(dep.name, dep.version_requirements).sort_by(&:version).last
139
+ }.compact.reject {|s| acc.include?(s) }.each do |dep|
140
+ collect_dependencies(dep, acc)
141
+ end
142
+
143
+ acc
144
+ end
100
145
  end
101
146
 
102
147
  Gem.post_install do |installer|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-depclean
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keita Urashima