Class: Nanoc3::CLI::Commands::Debug

Inherits:
Nanoc3::CLI::Command show all
Defined in:
lib/nanoc3/cli/commands/debug.rb

Instance Attribute Summary

Attributes inherited from Nanoc3::CLI::Command

#arguments, #command, #options

Instance Method Summary collapse

Methods inherited from Nanoc3::CLI::Command

#call, call, #initialize, #site

Constructor Details

This class inherits a constructor from Nanoc3::CLI::Command

Instance Method Details

#runObject



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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/nanoc3/cli/commands/debug.rb', line 18

def run
  # Make sure we are in a nanoc site directory
  print "Loading site data... "
  self.require_site
  puts "done"
  puts

  # Get data
  items   = self.site.items
  reps    = items.map { |i| i.reps }.flatten
  layouts = self.site.layouts

  # Get dependency tracker
  compiler = self.site.compiler
  compiler.load
  dependency_tracker = compiler.dependency_tracker

  # Print item dependencies
  puts '=== Item dependencies ======================================================='
  puts
  items.sort_by { |i| i.identifier }.each do |item|
    puts "item #{item.identifier} depends on:"
    predecessors = dependency_tracker.objects_causing_outdatedness_of(item).sort_by { |i| i ? i.identifier : '' }
    predecessors.each do |pred|
      if pred
        puts "  [ #{format '%6s', pred.type} ] #{pred.identifier}"
      else
        puts "  ( removed item )"
      end
    end
    puts "  (nothing)" if predecessors.empty?
    puts
  end

  # Print representation paths
  puts '=== Representation paths ===================================================='
  puts
  items.sort_by { |i| i.identifier }.each do |item|
    item.reps.sort_by { |r| r.name.to_s }.each do |rep|
      puts "item #{item.identifier}, rep #{rep.name}:"
      if rep.raw_paths.empty?
        puts "  (not written)"
      end
      length = rep.raw_paths.keys.map { |s| s.to_s.length }.max
      rep.raw_paths.each do |snapshot_name, raw_path|
        puts "  [ %-#{length}s ] %s" % [ snapshot_name, raw_path ]
      end
    end
    puts
  end

  # Print representation outdatedness
  puts '=== Representation outdatedness ============================================='
  puts
  items.sort_by { |i| i.identifier }.each do |item|
    item.reps.sort_by { |r| r.name.to_s }.each do |rep|
      puts "item #{item.identifier}, rep #{rep.name}:"
      outdatedness_reason = compiler.outdatedness_checker.outdatedness_reason_for(rep)
      if outdatedness_reason
        puts "  is outdated: #{outdatedness_reason.message}"
      else
        puts "  is not outdated"
      end
    end
    puts
  end

  # Print layout dependencies
  puts '=== Layout dependencies ====================================================='
  puts
  layouts.sort_by { |l| l.identifier }.each do |layout|
    puts "layout #{layout.identifier} depends on:"
    predecessors = dependency_tracker.objects_causing_outdatedness_of(layout).sort_by { |i| i ? i.identifier : '' }
    predecessors.each do |pred|
      if pred
        puts "  [ #{format '%6s', pred.type} ] #{pred.identifier}"
      else
        puts "  ( removed item )"
      end
    end
    puts "  (nothing)" if predecessors.empty?
    puts
  end

  # Print layouts
  puts '=== Layouts'
  puts
  layouts.sort_by { |l| l.identifier }.each do |layout|
    puts "layout #{layout.identifier}:"
    outdatedness_reason = compiler.outdatedness_checker.outdatedness_reason_for(layout)
    if outdatedness_reason
      puts "  is outdated: #{outdatedness_reason.message}"
    else
      puts "  is not outdated"
    end
    puts
  end
end