Class: Nanoc::CLI::Commands::Compile::FileActionPrinter

Inherits:
Listener
  • Object
show all
Defined in:
lib/nanoc/cli/commands/compile.rb

Overview

Prints file actions (created, updated, deleted, identical, skipped)

Instance Method Summary collapse

Methods inherited from Listener

enable_for?

Constructor Details

#initialize(reps:) ⇒ FileActionPrinter

Returns a new instance of FileActionPrinter



309
310
311
312
313
# File 'lib/nanoc/cli/commands/compile.rb', line 309

def initialize(reps:)
  @start_times = {}

  @reps = reps
end

Instance Method Details

#startObject

See Also:



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/nanoc/cli/commands/compile.rb', line 316

def start
  Nanoc::Int::NotificationCenter.on(:compilation_started) do |rep|
    @start_times[rep.raw_path] = Time.now
  end
  Nanoc::Int::NotificationCenter.on(:rep_written) do |_rep, path, is_created, is_modified|
    duration = path && @start_times[path] ? Time.now - @start_times[path] : nil
    action =
      if is_created then :create
      elsif is_modified then :update
      else :identical
      end
    level =
      if is_created then :high
      elsif is_modified then :high
      else :low
      end
    log(level, action, path, duration)
  end
end

#stopObject

See Also:



337
338
339
340
341
342
343
344
# File 'lib/nanoc/cli/commands/compile.rb', line 337

def stop
  super
  @reps.select { |r| !r.compiled? }.each do |rep|
    rep.raw_paths.each do |_snapshot_name, raw_path|
      log(:low, :skip, raw_path, nil)
    end
  end
end