Parent

Class/Module Index [+]

Quicksearch

Gem::Commands::TldrCommand

TL;DR your gems with gem tldr

Constants

VERSION

Public Class Methods

new() click to toggle source
# File lib/rubygems/commands/tldr_command.rb, line 12
def initialize
  super 'tldr', 'Documentation? Tests? They use too much disk space!'

  add_option '--dry-run', "don't do anything" do |value, options|
    options[:dry_run] = true
  end
end

Public Instance Methods

execute() click to toggle source
# File lib/rubygems/commands/tldr_command.rb, line 24
def execute
  @verbose = Gem.configuration.really_verbose

  if @verbose then
    if options[:dry_run] then
      extend FileUtils::DryRun
    else
      extend FileUtils::Verbose
    end
  elsif options[:dry_run] then
    extend FileUtils::NoWrite
  else
    extend FileUtils
  end

  beginning_size = total_size

  Gem.source_index.each do |name, spec|
    say "TL;DR #{name}"
    Dir.chdir spec.full_gem_path do
      remove_tests spec
      remove_built_documentation spec
      remove_build_artifacts spec
      remove_file_comments spec
    end
  end

  ending_size = total_size

  saved = beginning_size - ending_size

  say "start: #{beginning_size}B end: #{ending_size}B saved: #{saved}B"
end
remove_build_artifacts(spec) click to toggle source

Remove build artifacts for C extensions from spec

# File lib/rubygems/commands/tldr_command.rb, line 88
def remove_build_artifacts spec
  spec.extensions.each do |extension|
    next unless extension =~ /extconf\.rb$/
    extension_dir = File.dirname extension

    say "\tRemoving build artifacts in #{extension_dir}" if @verbose

    Dir["#{extension_dir}/**/*.{c,h,java,o}"].each do |artifact|
      rm_f artifact
    end

    Dir["#{extension_dir}/**/*.dSYM"].each do |artifact|
      rm_rf artifact
    end

    rm_f File.join(extension_dir, 'Makefile')
    rm_f File.join(extension_dir, 'extconf.rb')
    rm_f File.join(extension_dir, 'mkmf.log')
  end
end
remove_built_documentation(spec) click to toggle source

Remove the documentation for spec

# File lib/rubygems/commands/tldr_command.rb, line 78
def remove_built_documentation spec
  doc_dir = File.join spec.installation_path, 'doc', spec.full_name

  say "\tRemoving built documentation" if @verbose
  rm_rf doc_dir
end
remove_file_comments(spec) click to toggle source

Remove comments in the ruby files of spec

# File lib/rubygems/commands/tldr_command.rb, line 112
def remove_file_comments spec
  say "\tStripping comments" if @verbose
  return if options[:dry_run]
  spec.require_paths.each do |path|
    Dir["#{path}/**/*.rb"].each do |file|
      ruby = File.read file

      stripped = strip_comments ruby

      open file, 'w' do |io|
        io.write stripped
      end
    end
  end
end
remove_tests(spec) click to toggle source

Remove the tests (and specs) of spec

# File lib/rubygems/commands/tldr_command.rb, line 131
def remove_tests spec
  say "\tRemoving tests" if @verbose
  Dir['{test,spec}'].each do |dir|
    rm_rf dir
  end
end
strip_comments(ruby) click to toggle source

Strips comments out of ruby. Destructive!

# File lib/rubygems/commands/tldr_command.rb, line 141
def strip_comments ruby
  ruby.gsub!(/^[ \t]*#[^{@$].*?\r?\n/, '')
  ruby.gsub!(/[ \t]*#[^{@$].*?$/, '')
  ruby
end
total_size() click to toggle source

Find the total size of your Gem path directories

# File lib/rubygems/commands/tldr_command.rb, line 61
def total_size
  size = 0

  Gem.path.each do |directory|
    Find.find directory do |path|
      stat = File.stat path
      next unless stat.file?
      size += stat.size
    end
  end

  size
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.