gem-depclean 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/commands/world_command.rb +56 -37
  3. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
@@ -3,17 +3,16 @@ require 'rubygems/requirement'
3
3
  require 'yaml'
4
4
 
5
5
  class Gem::Commands::WorldCommand < Gem::Command
6
- Gem.post_install do |installer|
7
- command = Gem::CommandManager.instance['install']
8
- name = installer.spec.name
9
-
10
- begin
11
- if command.get_all_gem_names.include?(name)
12
- new.add name, command.options[:version]
13
- end
14
- rescue Gem::CommandLineError
15
- # called by 'gem update'
16
- end
6
+ def world_path
7
+ File.join(Gem.user_dir, 'world')
8
+ end
9
+
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
+ }
17
16
  end
18
17
 
19
18
  def initialize
@@ -30,7 +29,7 @@ class Gem::Commands::WorldCommand < Gem::Command
30
29
 
31
30
  def execute
32
31
  if options[:init]
33
- init_world
32
+ generate
34
33
  elsif options[:edit]
35
34
  edit
36
35
  else
@@ -38,7 +37,28 @@ class Gem::Commands::WorldCommand < Gem::Command
38
37
  end
39
38
  end
40
39
 
40
+ def generate
41
+ if File.exist?(world_path)
42
+ terminate_interaction unless ask_yes_no "'#{world_path}' is already exists. overwrite?"
43
+ end
44
+
45
+ open(world_path, 'w') do |f|
46
+ f << Gem.source_index.map(&:last).select {|spec|
47
+ spec.dependent_gems.empty?
48
+ }.group_by(&:name).inject({}) {|h, (name, specs)|
49
+ versions = specs.map(&:version).sort
50
+ versions[-1] = Gem::Requirement.default
51
+
52
+ h.merge(name => versions.map(&:to_s))
53
+ }.to_yaml
54
+ end
55
+
56
+ say "'#{world_path}' was successfully initialized."
57
+ end
58
+
41
59
  def edit
60
+ terminate_if_world_is_missing
61
+
42
62
  unless editor = ENV['VISUAL'] || ENV['EDITOR']
43
63
  alert_error 'Please set VISUAL or EDITOR variable.'
44
64
  terminate_interaction
@@ -47,6 +67,16 @@ class Gem::Commands::WorldCommand < Gem::Command
47
67
  system editor, world_path
48
68
  end
49
69
 
70
+ def list
71
+ terminate_if_world_is_missing
72
+
73
+ YAML.load_file(world_path).sort_by {|name, versions|
74
+ name.downcase
75
+ }.each do |name, versions|
76
+ say "#{name} (#{versions.join(', ')})"
77
+ end
78
+ end
79
+
50
80
  def add(name, version)
51
81
  open(world_path, 'r+') do |f|
52
82
  f << YAML.load(f).tap {|world|
@@ -59,36 +89,25 @@ class Gem::Commands::WorldCommand < Gem::Command
59
89
  end
60
90
  end
61
91
 
62
- def world_path
63
- File.join(Gem.user_dir, 'world')
64
- end
65
-
66
- def world_gems
67
- YAML.load_file(world_path).inject([]) {|acc, (name, versions)|
68
- acc + versions.map {|v|
69
- Gem.source_index.find_name(name, v).sort_by(&:version).last
70
- }.compact
71
- }
72
- end
92
+ private
73
93
 
74
- def list
75
- YAML.load_file(world_path).sort_by {|name, versions|
76
- name.downcase
77
- }.each do |name, versions|
78
- say "#{name} (#{versions.join(', ')})"
94
+ def terminate_if_world_is_missing
95
+ unless File.exist?(world_path)
96
+ alert_error "'#{world_path}' is missing. Please execute 'gem world --init'."
97
+ terminate_interaction
79
98
  end
80
99
  end
100
+ end
81
101
 
82
- def init_world
83
- open(world_path, 'w') do |f|
84
- f << Gem.source_index.map(&:last).select {|spec|
85
- spec.dependent_gems.empty?
86
- }.group_by(&:name).inject({}) {|h, (name, specs)|
87
- versions = specs.map(&:version).sort
88
- versions[-1] = Gem::Requirement.default
102
+ Gem.post_install do |installer|
103
+ command = Gem::CommandManager.instance['install']
104
+ name = installer.spec.name
89
105
 
90
- h.merge(name => versions.map(&:to_s))
91
- }.to_yaml
106
+ begin
107
+ if command.get_all_gem_names.include?(name)
108
+ Gem::Commands::WorldCommand.new.add name, command.options[:version]
92
109
  end
110
+ rescue Gem::CommandLineError
111
+ # called by 'gem update'
93
112
  end
94
113
  end
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.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keita Urashima