Class: Gem::Commands::DiffCommand

Inherits:
Gem::Command
  • Object
show all
Defined in:
lib/gem-diff/diff_command.rb,
lib/gem-diff/version.rb

Constant Summary collapse

VERSION =
'0.2'

Instance Method Summary collapse

Constructor Details

#initializeDiffCommand

Returns a new instance of DiffCommand.



3
4
5
# File 'lib/gem-diff/diff_command.rb', line 3

def initialize
  super 'diff', %q{Show differences between versions of gem}
end

Instance Method Details

#executeObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gem-diff/diff_command.rb', line 7

def execute
  if options[:args].empty?
    gems = Gem::Specification
  else
    gems = options[:args].map { |n| Gem::Specification.find_all_by_name(n) }.flatten
  end
  tree = {}
  gems.each do |gem|
    unless gem.default_gem?
      tree[gem.name] ||= []
      tree[gem.name] << gem
    end
  end
  tree.reject { |n, v| v.length < 2 }.each do |name, versions|
    versions.sort_by!(&:version)
    warn "#{name} has more than one version -- only comparing last two" if versions.length > 2
    paths = versions[-2..-1].map(&:gem_dir)
    system 'git', 'diff', *paths
  end
end