gem_snapshot 0.0.1

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.
@@ -0,0 +1,70 @@
1
+ require 'rubygems/install_update_options'
2
+
3
+ class Gem::Commands::SnapshotCommand < Gem::Command
4
+ include Gem::InstallUpdateOptions
5
+
6
+ def initialize
7
+ super('snapshot', "Dump and restore snapshots of installed rubygems", :file => nil)
8
+ add_option '-f', '--file=FILE', 'Snapshot file (default is stdin/stdout)' do |f, options|
9
+ options[:file] = f
10
+ end
11
+ add_install_update_options
12
+ end
13
+
14
+ def execute
15
+ case options[:args].first
16
+ when 'dump' then dump
17
+ when 'restore' then restore
18
+ else abort(usage)
19
+ end
20
+ end
21
+
22
+ def arguments
23
+ "ACTION (dump|restore)"
24
+ end
25
+
26
+ def usage
27
+ "#{program_name} ACTION"
28
+ end
29
+
30
+ def description
31
+ <<TEXT
32
+ Allows you to easily dump a snapshot of all installed gems in an environment
33
+ and then restore the snapshot to installed gems.
34
+ TEXT
35
+ end
36
+
37
+ private
38
+
39
+ def restore
40
+ input =
41
+ if options[:file] then File.open(options[:file], 'r')
42
+ else STDIN
43
+ end
44
+ YAML.load(input).each_pair do |gem, versions|
45
+ versions.each do |version|
46
+ installed = Gem.source_index.find_name(gem, version)
47
+ if installed.empty?
48
+ puts "Installing #{gem} #{version}"
49
+ installer = Gem::DependencyInstaller.new(options).install(gem, version)
50
+ else
51
+ puts "Already have #{gem} #{version}"
52
+ end
53
+ end
54
+ end
55
+ input.close
56
+ end
57
+
58
+ def dump
59
+ out =
60
+ if options[:file] then File.open(options[:file], 'w')
61
+ else STDOUT
62
+ end
63
+ specs = Hash.new { |h, k| h[k] = [] }
64
+ Gem.source_index.each do |name, specification|
65
+ specs[specification.name] << specification.version.to_s
66
+ end
67
+ out.puts specs.to_yaml
68
+ out.close
69
+ end
70
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems/command_manager'
2
+
3
+ Gem::CommandManager.instance.register_command :snapshot
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem_snapshot
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Mat Brown
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-20 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: |
23
+ Gem plugin that provides two new rubygems commands, `gem dump' and
24
+ `gem restore'. The `dump' command outputs a manifest of installed gems in YAML
25
+ (either to a file or STDOUT), and the `restore' command reads a dump and installs
26
+ all gems that aren't already installed.
27
+
28
+ email: mat@patch.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - ./lib/rubygems/commands/snapshot_command.rb
37
+ - ./lib/rubygems_plugin.rb
38
+ has_rdoc: true
39
+ homepage:
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project: gem_snapshot
68
+ rubygems_version: 1.3.7
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Dump and restore snapshot of installed gems.
72
+ test_files: []
73
+