Narnach-gems 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/README.rdoc +14 -2
  2. data/bin/gems +13 -1
  3. data/gems.gemspec +2 -2
  4. data/lib/gems.rb +70 -33
  5. data/lib/gems_list.rb +30 -0
  6. metadata +2 -1
data/README.rdoc CHANGED
@@ -5,8 +5,14 @@ Rails code would not get into dependency issues.
5
5
 
6
6
  == Recent changes
7
7
 
8
+ === Version 0.1.7
9
+ Gem install only installs missing gems; it does not re-install gems.
10
+
11
+ === Version 0.1.6
12
+ Added gems diff and gems switch commands to make it easy to compare and switch the gems of multiple projects.
13
+
8
14
  === Version 0.1.5
9
- Gem import accepts 'current' as a special file name, which will use the output
15
+ Gems import accepts 'current' as a special file name, which will use the output
10
16
  of 'gem list' instead of a real file. This makes it easy to store the current gem configuration.
11
17
 
12
18
  === Version 0.1.4
@@ -50,9 +56,15 @@ Output if 'gems help', with some changes to make them legible in RDoc:
50
56
 
51
57
  Actions and arguments:
52
58
  install 'name'
53
- Install all gems in project 'name'.
59
+ Install all missing gems in project 'name'.
54
60
  uninstall 'name'
55
61
  Uninstall all gems in project 'name'.
62
+ diff 'name'
63
+ See difference between the current gem configuration and that of project 'name'.
64
+ switch 'name'
65
+ Switch to the exact gem configuration in project 'name'.
66
+ This will preserve all shared gems in the current state and in the target
67
+ project, only installing and uninstalling what is needed.
56
68
  list 'name'
57
69
  List all gems in project 'name'.
58
70
  import 'name' 'file'
data/bin/gems CHANGED
@@ -35,6 +35,12 @@ when 'add'
35
35
  gems_config = GemsConfig.new(project)
36
36
  gems_file = ARGV.shift.to_s.strip
37
37
  gems_config.add_gems(gems_file)
38
+ when 'diff'
39
+ gems = Gems.new project
40
+ gems.diff_current
41
+ when 'switch'
42
+ gems = Gems.new project
43
+ gems.switch_from_current
38
44
  else 'help'
39
45
  puts <<-EOS
40
46
  Syntax:
@@ -42,9 +48,15 @@ Syntax:
42
48
 
43
49
  Actions and arguments:
44
50
  install <name>
45
- Install all gems in project <name>.
51
+ Install all missing gems in project <name>.
46
52
  uninstall <name>
47
53
  Uninstall all gems in project <name>.
54
+ diff <name>
55
+ See difference between the current gem configuration and that of project <name>.
56
+ switch <name>
57
+ Switch to the exact gem configuration in project <name>.
58
+ This will preserve all shared gems in the current state and in the target
59
+ project, only installing and uninstalling what is needed.
48
60
  list <name>
49
61
  List all gems in project <name>.
50
62
  import <name> <file>
data/gems.gemspec CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
3
3
  s.name = 'gems'
4
4
  s.summary = "Gems is a simple tool to manage sets of RubyGems."
5
5
  s.description = "Gems is a simple tool to manage sets of RubyGems. It can be used to install and uninstall large numbers of gems."
6
- s.version = '0.1.5'
6
+ s.version = '0.1.7'
7
7
  s.date = '2008-08-19'
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Wes Oldenbeuving"]
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.bindir = "bin"
15
15
  s.executables = %w[gems]
16
16
  s.require_path = "lib"
17
- s.files = ['MIT-LICENSE', 'README.rdoc', 'Rakefile', 'bin/gems', 'lib/gems.rb', 'lib/gems_config.rb', 'lib/gems_parser.rb', 'gems.gemspec']
17
+ s.files = ['MIT-LICENSE', 'README.rdoc', 'Rakefile', 'bin/gems', 'lib/gems.rb', 'lib/gems_config.rb', 'lib/gems_parser.rb', 'gems.gemspec', 'lib/gems_list.rb']
18
18
  s.test_files = []
19
19
 
20
20
  # rdoc
data/lib/gems.rb CHANGED
@@ -1,4 +1,12 @@
1
1
  require 'gems_config'
2
+ require 'gems_parser'
3
+ require 'gems_list'
4
+
5
+ class Hash
6
+ def longest_key_length
7
+ map{|key, value| key.to_s.size}.max || 0
8
+ end
9
+ end
2
10
 
3
11
  class Gems
4
12
  attr_reader :project, :gems, :gems_config
@@ -9,28 +17,63 @@ class Gems
9
17
  @gems = @gems_config.gems
10
18
  end
11
19
 
20
+ def diff_current
21
+ current_gems = GemsList.new(GemsParser.new('current').gems)
22
+ project_gems = GemsList.new(gems)
23
+ not_in_current = project_gems - current_gems
24
+ in_current = current_gems - project_gems
25
+
26
+ puts 'Gems unique to "%s":' % project
27
+ print_gem_list(not_in_current)
28
+ puts
29
+ puts 'Gems unique to the current gems list:'
30
+ print_gem_list(in_current)
31
+ end
32
+
12
33
  def list
13
34
  puts 'Gems in "%s":' % project
14
- gems.each do |gemname, versions|
15
- line = "%#{longest_gem_name_length}s %s" % [gemname, versions.join(", ")]
16
- if gems_config.options_for(gemname).size > 0
17
- line << ' [%s]' % gems_config.options_for(gemname).join(" ")
18
- end
19
- puts line
20
- end
35
+ print_gem_list(gems)
21
36
  end
22
37
 
23
38
  def install
24
39
  puts "Installing all gems and versions in '%s'" % project
40
+ install_gems_list(GemsList.new(gems) - current_gems_list)
41
+ end
42
+
43
+ def switch_from_current
44
+ current_gems = current_gems_list
45
+ project_gems = GemsList.new(gems)
46
+
47
+ to_install = project_gems - current_gems
48
+ to_uninstall = current_gems - project_gems
49
+
50
+ install_gems_list(to_install)
51
+ uninstall_gems_list(to_uninstall)
52
+ end
53
+
54
+ def uninstall
55
+ puts "Uninstalling all gems and versions in '%s'" % project
56
+ uninstall_gems_list(GemsList.new(gems))
57
+ end
58
+
59
+ private
60
+
61
+ def current_gems_list
62
+ @current_gems_list ||= GemsParser.new('current').gems
63
+ end
64
+
65
+ def install_gems_list(gems)
25
66
  results = {}
26
- each_gem_with_version do |gemname, version|
27
- cmd = "sudo gem install --ignore-dependencies --no-rdoc --no-ri -v %s %s" % [version, gemname]
28
- if gems_config.options_for(gemname).size > 0
29
- cmd << ' -- %s' % gems_config.options_for(gemname).join(" ")
67
+ gems.each_gem_with_version do |gemname, versions|
68
+ versions.each do |version|
69
+ cmd = "sudo gem install --ignore-dependencies --no-rdoc --no-ri -v %s %s > /dev/null" % [version, gemname]
70
+ if gems_config.options_for(gemname).size > 0
71
+ cmd << ' -- %s' % gems_config.options_for(gemname).join(" ")
72
+ end
73
+ puts cmd
74
+ result = system(cmd)
75
+ results['%s-%s' % [gemname, version]] = result
30
76
  end
31
- puts cmd
32
- result = system(cmd)
33
- results['%s-%s' % [gemname, version]] = result
34
77
  end
35
78
  successful = results.select {|gemname, success| success}
36
79
  unsuccessful = results.select {|gemname, success| !success}
@@ -40,11 +83,20 @@ class Gems
40
83
  puts "Failed to install: %s" % unsuccessful.map{|ary| ary[0]}.sort.join(", ")
41
84
  end
42
85
 
43
- def uninstall
44
- puts "Uninstalling all gems and versions in '%s'" % project
86
+ def print_gem_list(gems)
87
+ gems.each do |gemname, versions|
88
+ line = "%#{gems.longest_key_length}s %s" % [gemname, versions.join(", ")]
89
+ if gems_config.options_for(gemname).size > 0
90
+ line << ' [%s]' % gems_config.options_for(gemname).join(" ")
91
+ end
92
+ puts line
93
+ end
94
+ end
95
+
96
+ def uninstall_gems_list(gems)
45
97
  results = {}
46
- each_gem_with_version do |gemname, version|
47
- cmd = "sudo gem uninstall --ignore-dependencies --executables -v %s %s" % [version, gemname]
98
+ gems.each_gem_with_version do |gemname, version|
99
+ cmd = "sudo gem uninstall --ignore-dependencies --executables -v %s %s > /dev/null" % [version, gemname]
48
100
  puts cmd
49
101
  result = system(cmd)
50
102
  results['%s-%s' % [gemname, version]] = result
@@ -56,19 +108,4 @@ class Gems
56
108
  puts
57
109
  puts "Failed to uninstall: %s" % unsuccessful.map{|ary| ary[0]}.sort.join(", ")
58
110
  end
59
-
60
- private
61
-
62
- def each_gem_with_version(&block)
63
- raise ArgumentError, 'No block provided' unless block
64
- gems.each do |gemname, versions|
65
- versions.each do |version|
66
- block.call(gemname, version)
67
- end
68
- end
69
- end
70
-
71
- def longest_gem_name_length
72
- gems.map{|ary| ary[0].size}.max
73
- end
74
111
  end
data/lib/gems_list.rb ADDED
@@ -0,0 +1,30 @@
1
+ class GemsList < Hash
2
+ def initialize(hsh={})
3
+ hsh.each do |key, value|
4
+ self[key] = value
5
+ end
6
+ end
7
+
8
+ def -(other)
9
+ diff = GemsList.new
10
+ self.each do |gem, versions|
11
+ if other.has_key?(gem)
12
+ other_versions = other[gem]
13
+ versions_unique_to_current = versions - other_versions
14
+ diff[gem] = versions_unique_to_current if versions_unique_to_current.size > 0
15
+ else
16
+ diff[gem] = versions
17
+ end
18
+ end
19
+ diff
20
+ end
21
+
22
+ def each_gem_with_version(&block)
23
+ raise ArgumentError, 'No block provided' unless block
24
+ self.each do |gemname, versions|
25
+ versions.each do |version|
26
+ block.call(gemname, version)
27
+ end
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Narnach-gems
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wes Oldenbeuving
@@ -31,6 +31,7 @@ files:
31
31
  - lib/gems_config.rb
32
32
  - lib/gems_parser.rb
33
33
  - gems.gemspec
34
+ - lib/gems_list.rb
34
35
  has_rdoc: true
35
36
  homepage: http://www.github.com/Narnach/gems
36
37
  post_install_message: