gem-prune 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1 @@
1
- module GemPrune
2
- VERSION = "2.0.1"
3
- end
1
+ require "gem_prune"
@@ -1,8 +1,11 @@
1
- require 'rubygems/command'
2
- require 'rubygems/command_manager'
1
+ require "rubygems/command"
2
+ require "rubygems/command_manager"
3
+ require "gem/prune/util"
3
4
 
4
5
  class Gem::Commands::KeepCommand < Gem::Command
5
6
 
7
+ include Gem::Prune::Util
8
+
6
9
  def initialize
7
10
  super 'keep', 'Mark a gem for keeping'
8
11
 
@@ -13,54 +16,14 @@ class Gem::Commands::KeepCommand < Gem::Command
13
16
  end
14
17
 
15
18
  def execute
16
- gem = get_one_gem_name
19
+ keep_gem = get_one_gem_name
17
20
  load_configuration
18
- gems_to_keep[gem] ||= []
19
- gems_to_keep[gem] << options[:version]
20
- gems_to_keep[gem] = gems_to_keep[gem].uniq.compact
21
+ entry = gems_to_keep.detect { |(gem, versions)| gem == keep_gem }
22
+ entry[1] << options[:version]
23
+ entry[1] = entry[1].uniq.compact
21
24
  save_configuration
22
25
  end
23
26
 
24
27
  private ######################################################################
25
28
 
26
- def load_configuration
27
- @configuration ||= begin
28
- config = YAML::load_file(settings_filename)
29
- config = upgrade_configuration(config) if config.first.first == "keep"
30
- unpack_configuration(config)
31
- end
32
- end
33
-
34
- def save_configuration
35
- File.open(settings_filename, "w") do |file|
36
- file.puts(YAML::dump(pack_configuration(@configuration)))
37
- end
38
- end
39
-
40
- def unpack_configuration(config)
41
- config.inject({}) do |memo, (gem, keep)|
42
- memo.update(gem => keep)
43
- end
44
- end
45
-
46
- def pack_configuration(config)
47
- config.map do |gem, keep|
48
- [gem, keep]
49
- end.sort_by(&:first)
50
- end
51
-
52
- def upgrade_configuration(config)
53
- config["keep"].map do |gem|
54
- [gem, []]
55
- end
56
- end
57
-
58
- def gems_to_keep
59
- @configuration
60
- end
61
-
62
- def settings_filename
63
- File.expand_path('~/.gem-prune')
64
- end
65
-
66
29
  end
@@ -1,11 +1,14 @@
1
- require 'rubygems/command'
2
- require 'rubygems/command_manager'
3
- require 'rubygems/uninstaller'
4
- require 'gem/prune/gem'
5
- require 'gem/prune/version'
1
+ require "rubygems/command"
2
+ require "rubygems/command_manager"
3
+ require "rubygems/uninstaller"
4
+ require "gem/prune/gem"
5
+ require "gem/prune/version"
6
+ require "gem/prune/util"
6
7
 
7
8
  class Gem::Commands::PruneCommand < Gem::Command
8
9
 
10
+ include Gem::Prune::Util
11
+
9
12
  def initialize
10
13
  super 'prune', 'Identify and remove old gems'
11
14
  end
@@ -51,42 +54,6 @@ private ######################################################################
51
54
  end
52
55
  end
53
56
 
54
- def load_configuration
55
- @configuration ||= begin
56
- config = YAML::load_file(settings_filename)
57
- config = upgrade_configuration(config) if config.first.first == "keep"
58
- unpack_configuration(config)
59
- end
60
- end
61
-
62
- def save_configuration
63
- File.open(settings_filename, "w") do |file|
64
- file.puts(YAML::dump(pack_configuration(@configuration)))
65
- end
66
- end
67
-
68
- def unpack_configuration(config)
69
- config.inject({}) do |memo, (gem, keep)|
70
- memo.update(gem => keep)
71
- end
72
- end
73
-
74
- def pack_configuration(config)
75
- config.map do |gem, keep|
76
- [gem, keep]
77
- end.sort_by(&:first)
78
- end
79
-
80
- def upgrade_configuration(config)
81
- config["keep"].map do |gem|
82
- [gem, []]
83
- end
84
- end
85
-
86
- def gems_to_keep
87
- @configuration
88
- end
89
-
90
57
  def mark_kept_versions
91
58
  gems.each do |name, gem|
92
59
  mark_kept(gem.versions.sort.last)
@@ -110,20 +77,8 @@ private ######################################################################
110
77
  version.dependencies.each { |v| mark_kept(v) }
111
78
  end
112
79
 
113
- def versions_to_keep
114
- versions_with_kept_flag(true)
115
- end
116
-
117
80
  def versions_to_prune
118
- versions_with_kept_flag(false)
119
- end
120
-
121
- def versions_with_kept_flag(value)
122
- gems.map { |name, gem| gem.versions }.flatten.select { |v| v.keep == value }
123
- end
124
-
125
- def settings_filename
126
- File.expand_path('~/.gem-prune')
81
+ gems.map { |name, gem| gem.versions }.flatten.select { |v| v.keep == false }
127
82
  end
128
83
 
129
84
  end
@@ -0,0 +1,30 @@
1
+ module Gem; module Prune; module Util
2
+
3
+ def settings_filename
4
+ File.expand_path('~/.gem-prune')
5
+ end
6
+
7
+ def gems_to_keep
8
+ @configuration
9
+ end
10
+
11
+ def load_configuration
12
+ @configuration ||= File.read(settings_filename).split("\n").map do |line|
13
+ gem, versions = line.split(' ', 2)
14
+ versions = versions.to_s.gsub(/[\(\)]/, '').split(', ')
15
+ [gem, versions]
16
+ end
17
+ end
18
+
19
+ def save_configuration
20
+ File.open(settings_filename, "w") do |file|
21
+ formatted = @configuration.map do |gem, versions|
22
+ version_string = versions.length.zero? ? "" : " (%s)" % versions.join(", ")
23
+ "#{gem}#{version_string}"
24
+ end.join("\n")
25
+
26
+ file.puts formatted
27
+ end
28
+ end
29
+
30
+ end; end; end
@@ -0,0 +1,3 @@
1
+ module GemPrune
2
+ VERSION = "2.1.0"
3
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-prune
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
- - 0
9
8
  - 1
10
- version: 2.0.1
9
+ - 0
10
+ version: 2.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - |
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-08-30 00:00:00 -04:00
20
+ date: 2010-10-02 00:00:00 -04:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -97,7 +97,9 @@ files:
97
97
  - lib/gem/commands/keep_command.rb
98
98
  - lib/gem/commands/prune_command.rb
99
99
  - lib/gem/prune/gem.rb
100
+ - lib/gem/prune/util.rb
100
101
  - lib/gem/prune/version.rb
102
+ - lib/gem_prune.rb
101
103
  - lib/rubygems_plugin.rb
102
104
  - spec/gem-prune_spec.rb
103
105
  - spec/spec_helper.rb