Class: Nanoc::CLI::CompileListeners::FileActionPrinter Private

Inherits:
Abstract
  • Object
show all
Defined in:
lib/nanoc/cli/compile_listeners/file_action_printer.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Methods inherited from Abstract

enable_for?, #on, #run_while, #start_safely, #stop_safely, #wrapped_start, #wrapped_stop

Constructor Details

#initialize(reps:) ⇒ FileActionPrinter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of FileActionPrinter.



5
6
7
8
9
# File 'lib/nanoc/cli/compile_listeners/file_action_printer.rb', line 5

def initialize(reps:)
  @reps = reps

  @stopwatches = {}
end

Instance Method Details

#startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

See Also:

  • Listener#start


12
13
14
15
16
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
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
# File 'lib/nanoc/cli/compile_listeners/file_action_printer.rb', line 12

def start
  on(:compilation_started) do |rep|
    @stopwatches[rep] ||= DDMetrics::Stopwatch.new
    @stopwatches[rep].start
  end

  on(:compilation_suspended) do |rep|
    @stopwatches[rep].stop
  end

  cached_reps = Set.new
  on(:cached_content_used) do |rep|
    cached_reps << rep
  end

  on(:rep_write_enqueued) do |rep|
    @stopwatches[rep].stop
  end

  on(:rep_write_started) do |rep, _raw_path|
    @stopwatches[rep].start
  end

  on(:rep_write_ended) do |rep, _binary, path, is_created, is_modified|
    @stopwatches[rep].stop
    duration = @stopwatches[rep].duration

    action =
      if is_created
        :create
      elsif is_modified
        :update
      elsif cached_reps.include?(rep)
        :cached
      else
        :identical
      end
    level =
      if is_created
        :high
      elsif is_modified
        :high
      else
        :low
      end

    # Make path relative (to current working directory)
    # FIXME: do not depend on working directory
    if path.start_with?(Dir.getwd)
      path = path[(Dir.getwd.size + 1)..path.size]
    end

    log(level, action, path, duration)
  end

  on(:file_pruned) do |path|
    # Make path relative (to current working directory)
    # FIXME: do not depend on working directory
    if path.start_with?(Dir.getwd)
      path = path[(Dir.getwd.size + 1)..path.size]
    end

    Nanoc::CLI::Logger.instance.file(:high, :delete, path)
  end

  on(:file_listed_for_pruning) do |path|
    # Make path relative (to current working directory)
    # FIXME: do not depend on working directory
    if path.start_with?(Dir.getwd)
      path = path[(Dir.getwd.size + 1)..path.size]
    end

    Nanoc::CLI::Logger.instance.file(:high, :delete, '(dry run) ' + path)
  end
end

#stopObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

See Also:

  • Listener#stop


89
90
91
92
93
94
95
96
# File 'lib/nanoc/cli/compile_listeners/file_action_printer.rb', line 89

def stop
  @reps.reject(&:compiled?).each do |rep|
    raw_paths = rep.raw_paths.values.flatten.uniq
    raw_paths.each do |raw_path|
      log(:low, :skip, raw_path, nil)
    end
  end
end