Class: YARD::CLI::Diff

Inherits:
Command show all
Defined in:
lib/yard/cli/diff.rb

Overview

CLI command to return the objects that were added/removed from 2 versions of a project (library, gem, working copy).

Since:

  • 0.6.0

Instance Method Summary collapse

Methods inherited from Command

#common_options, #load_script, #parse_options, run

Constructor Details

#initializeDiff

Returns a new instance of Diff.

Since:

  • 0.6.0


11
12
13
14
15
16
# File 'lib/yard/cli/diff.rb', line 11

def initialize
  require_rubygems
  super
  @list_all = false
  log.show_backtraces = true
end

Instance Method Details

#descriptionObject

Since:

  • 0.6.0


18
19
20
# File 'lib/yard/cli/diff.rb', line 18

def description
  'Returns the object diff of two gems or .yardoc files'
end

#run(*args) ⇒ Object

Since:

  • 0.6.0


22
23
24
25
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
52
53
54
55
56
# File 'lib/yard/cli/diff.rb', line 22

def run(*args)
  registry = optparse(*args).map do |gemfile|
    if load_gem_data(gemfile)
      log.info "Found #{gemfile}"
      Registry.all.map {|o| o.path }
    else
      log.error "Cannot find gem #{gemfile}"
      nil
    end
  end.compact
  
  return if registry.size != 2

  [   ["Added objects", registry[1] - registry[0]],
      ["Removed objects", registry[0] - registry[1]]].each do |name, objects|
    next if objects.empty?
    last_object = nil
    all_objects_notice = false
    puts name + ":"
    objects.sort.each do |object|
      if !@list_all && last_object && object =~ /#{Regexp.quote last_object}(::|\.|#)/
        print " (...)" unless all_objects_notice
        all_objects_notice = true
        next
      else
        puts
      end
      all_objects_notice = false
      print "  " + object
      last_object = object
    end
    puts
    puts
  end
end