Class: Gem::Commands::CacheCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::CacheCommand
- Defined in:
- lib/rubygems/commands/cache_command.rb
Instance Method Summary collapse
- #description ⇒ Object
- #execute ⇒ Object
-
#initialize ⇒ CacheCommand
constructor
A new instance of CacheCommand.
- #usage ⇒ Object
Constructor Details
#initialize ⇒ CacheCommand
Returns a new instance of CacheCommand.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rubygems/commands/cache_command.rb', line 5 def initialize super 'cache', 'Cache your current path for fast loading' add_option('-p', '--path PATH', 'Path to use instead of the default, separated by `:\'') do |value,| $:.replace value.split(':') end add_option('-d', '--with-dir DIR', 'Directory that should be included in the cache') do |dir,| $:.unshift dir end add_option('-o', '--output-file FILE', 'The file in which the cache is placed') do |f,| [:output] = f end end |
Instance Method Details
#description ⇒ Object
21 22 23 |
# File 'lib/rubygems/commands/cache_command.rb', line 21 def description 'A RubyGems plugin that takes an image of your gem structure and caches it to allow for a faster require time.' end |
#execute ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rubygems/commands/cache_command.rb', line 29 def execute [:output] ||= File.("~/.gem/cache") puts "Caching gem structure" tree = Trie.new; names = []; i = 0 $:.each do |dir| (Dir["#{dir}/*.rb"] + Dir["#{dir}/lib/**/*.rb"]).each do |file| names << file tree.add file[dir.size+1..-4], i i += 1 end end File.open([:output]+".list", File::CREAT|File::TRUNC|File::RDWR) do |f| f.write Marshal.dump names end tree.save([:output]) end |
#usage ⇒ Object
25 26 27 |
# File 'lib/rubygems/commands/cache_command.rb', line 25 def usage "#{program_name} [-p PATH] [-d DIR]" end |