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

Constructor Details

#initializeDiff

Returns a new instance of Diff.

Since:

  • 0.6.0



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/yard/cli/diff.rb', line 11

def initialize
  super
  @list_all = false
  @use_git = false
  @compact = false
  @modified = true
  @verifier = Verifier.new
  @old_git_commit = nil
  @old_path = Dir.pwd
  log.show_backtraces = true
end

Instance Method Details

#descriptionObject

Since:

  • 0.6.0



23
24
25
# File 'lib/yard/cli/diff.rb', line 23

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

#run(*args) ⇒ Object

Since:

  • 0.6.0



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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/yard/cli/diff.rb', line 27

def run(*args)
  registry = optparse(*args).map do |gemfile|
    if @use_git
      load_git_commit(gemfile)
      all_objects
    else
      if load_gem_data(gemfile)
        log.info "Found #{gemfile}"
        all_objects
      else
        log.error "Cannot find gem #{gemfile}"
        nil
      end
    end
  end.compact

  return if registry.size != 2

  first_object = nil
  [   ["Added objects", "A", added_objects(*registry)],
      ["Modified objects", "M", modified_objects(*registry)],
      ["Removed objects", "D", removed_objects(*registry)]].each do |name, short, objects|
    next if short == "M" && @modified == false
    next if objects.empty?
    last_object = nil
    all_objects_notice = false
    log.puts name + ":" unless @compact
    objects.sort_by {|o| o.path }.each do |object|
      if !@list_all && last_object && object.parent == last_object
        log.print " (...)" unless all_objects_notice
        all_objects_notice = true
        next
      elsif @compact
        log.puts if first_object
      else
        log.puts
      end
      all_objects_notice = false
      log.print "" + (@compact ? "#{short} " : "  ") +
        object.path + " (#{object.file}:#{object.line})"
      last_object = object
      first_object = true
    end
    unless @compact
      log.puts; log.puts
    end
  end
  log.puts if @compact
end