Class: Gem::Commands::RecentUpdatesCommand

Inherits:
Gem::Command
  • Object
show all
Defined in:
lib/rubygems/commands/recent-updates_command.rb

Instance Method Summary collapse

Constructor Details

#initializeRecentUpdatesCommand

Returns a new instance of RecentUpdatesCommand.



5
6
7
8
9
10
11
# File 'lib/rubygems/commands/recent-updates_command.rb', line 5

def initialize
  super 'recent-updates', "Display the recent histories of recently updated gems"

  add_option('--since TIME', Float, 'Number of days back to look') do |value, options|
    options[:days] = value
  end
end

Instance Method Details

#descriptionObject

:nodoc:



13
14
15
# File 'lib/rubygems/commands/recent-updates_command.rb', line 13

def description # :nodoc:
  """Displays the new portions of the history files of recently updated gems."""
end

#executeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rubygems/commands/recent-updates_command.rb', line 17

def execute
  days = options[:days] || 7
  since = Time.now - days * 24 * 60 * 60
  names = Gem.source_index.map do |name, spec|
    mtime = Dir["#{spec.full_gem_path}/**/*.*"].map { |file|
      File.mtime(file)
    }.min
    spec if mtime > since
  end.compact

  run_pager

  changes = names.map do |spec|
    name, version = spec.name, spec.version
    dep = Gem::Dependency.new name, Gem::Requirement.default
    specs = Gem.source_index.search dep
    prev = specs.select { |s| s.version < version }.sort.last
    next unless prev
    "#{Term::ANSIColor::red}#{name} #{version.version}#{Term::ANSIColor::black}:\n" +
      change_summary(spec, prev) + "\n"
  end.compact

  if changes.any?
    puts "Changes since #{since}:\n\n"
    puts changes.join("\n")
  else
    puts "No changes since #{since}."
  end
end