Class: Gem::Commands::DumpCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::DumpCommand
- Defined in:
- lib/rubygems/commands/dump_command.rb
Constant Summary collapse
- VERSION =
"0.0.1"
- FNAME =
"/.gemfile"
Instance Method Summary collapse
-
#arguments ⇒ Object
:nodoc:.
-
#defaults_str ⇒ Object
:nodoc:.
- #execute ⇒ Object
-
#initialize ⇒ DumpCommand
constructor
A new instance of DumpCommand.
-
#usage ⇒ Object
:nodoc:.
Constructor Details
#initialize ⇒ DumpCommand
Returns a new instance of DumpCommand.
9 10 11 12 |
# File 'lib/rubygems/commands/dump_command.rb', line 9 def initialize super("dump", "\"Dump\" all your gems to a ~/.gemfile", :version => Gem::Requirement.default) end |
Instance Method Details
#arguments ⇒ Object
:nodoc:
14 15 16 |
# File 'lib/rubygems/commands/dump_command.rb', line 14 def arguments # :nodoc: 'FILE dumps to another file' end |
#defaults_str ⇒ Object
:nodoc:
18 19 20 |
# File 'lib/rubygems/commands/dump_command.rb', line 18 def defaults_str # :nodoc: "--version='>= 0'" end |
#execute ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rubygems/commands/dump_command.rb', line 26 def execute path ||= ENV['HOME'] unless path puts "No path to write.."; return end gems = `gem list --no-version`.split("\n") all = nil unless File.exists?(fname = path + FNAME) file = File.new(fname, "w+") file.puts "# Mygems dump #{Time.now}. #{gems.length} gems." file.puts else file = File.new(fname, "a+") all = file.readlines.map{ |l| l.match(/"([^\"]*)"/)[1] rescue nil }.reject(&:nil?) gems -= all return if gems.empty? file.puts file.puts "# New gems #{Time.now}." file.puts end for gem in gems file.puts "gem \"#{gem}\"" end file.close puts "Gemfile written. #{fname}" end |
#usage ⇒ Object
:nodoc:
22 23 24 |
# File 'lib/rubygems/commands/dump_command.rb', line 22 def usage # :nodoc: "#{program_name} [PATH]" end |