Class: Nanoc::CLI::Commands::Compile::DiffGenerator Private
- Defined in:
- lib/nanoc/cli/commands/compile.rb
Overview
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.
Generates diffs for every output file written
Class Method Summary collapse
Instance Method Summary collapse
- #start ⇒ Object private
- #stop ⇒ Object private
Methods inherited from Listener
#initialize, #start_safely, #stop_safely
Constructor Details
This class inherits a constructor from Nanoc::CLI::Commands::Compile::Listener
Class Method Details
.enable_for?(command_runner) ⇒ Boolean
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.
70 71 72 |
# File 'lib/nanoc/cli/commands/compile.rb', line 70 def self.enable_for?(command_runner) command_runner.site.config[:enable_output_diff] end |
Instance Method Details
#start ⇒ Object
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.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/nanoc/cli/commands/compile.rb', line 75 def start require 'tempfile' setup_diffs old_contents = {} Nanoc::Int::NotificationCenter.on(:will_write_rep, self) do |rep, path| old_contents[rep] = File.file?(path) ? File.read(path) : nil end Nanoc::Int::NotificationCenter.on(:rep_written, self) do |rep, path, _is_created, _is_modified| unless rep.binary? new_contents = File.file?(path) ? File.read(path) : nil if old_contents[rep] && new_contents generate_diff_for(path, old_contents[rep], new_contents) end old_contents.delete(rep) end end end |
#stop ⇒ Object
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.
94 95 96 97 98 99 100 101 |
# File 'lib/nanoc/cli/commands/compile.rb', line 94 def stop super Nanoc::Int::NotificationCenter.remove(:will_write_rep, self) Nanoc::Int::NotificationCenter.remove(:rep_written, self) teardown_diffs end |