lib/nanoc/cli/commands/compile.rb in nanoc-3.7.3 vs lib/nanoc/cli/commands/compile.rb in nanoc-3.7.4

- old
+ new

@@ -1,9 +1,9 @@ # encoding: utf-8 -usage 'compile [options]' -summary 'compile items of this site' +usage 'compile [options]' +summary 'compile items of this site' description <<-EOS Compile all items of the current site. The compile command will show all items of the site as they are processed. The time spent compiling the item will be printed, as well as a status message, which can be one of the following: @@ -31,19 +31,19 @@ # and set up notifications to listen to. # # @abstract Subclasses must override {#start} and may override {#stop}. class Listener - def initialize(params = {}) + def initialize(_params = {}) end # @param [Nanoc::CLI::CommandRunner] command_runner The command runner for this listener # # @return [Boolean] true if this listener should be enabled for the given command runner, false otherwise # # @abstract Returns `true` by default, but subclasses may override this. - def self.enable_for?(command_runner) + def self.enable_for?(_command_runner) true end # Starts the listener. Subclasses should override this method and set up listener notifications. # @@ -77,12 +77,12 @@ old_contents = {} Nanoc::NotificationCenter.on(:will_write_rep) do |rep, snapshot| path = rep.raw_path(:snapshot => snapshot) old_contents[rep] = File.file?(path) ? File.read(path) : nil end - Nanoc::NotificationCenter.on(:rep_written) do |rep, path, is_created, is_modified| - if !rep.binary? + Nanoc::NotificationCenter.on(:rep_written) 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(rep, old_contents[rep], new_contents) end old_contents.delete(rep) @@ -94,11 +94,11 @@ def stop super teardown_diffs end - protected + protected def setup_diffs @diff_lock = Mutex.new @diff_threads = [] FileUtils.rm('output.diff') if File.file?('output.diff') @@ -135,12 +135,12 @@ old_file.flush new_file.write(b) new_file.flush # Diff - cmd = [ 'diff', '-u', old_file.path, new_file.path ] - Open3.popen3(*cmd) do |stdin, stdout, stderr| + cmd = ['diff', '-u', old_file.path, new_file.path] + Open3.popen3(*cmd) do |_stdin, stdout, _stderr| result = stdout.read return (result == '' ? nil : result) end end end @@ -167,36 +167,36 @@ @reps = params.fetch(:reps) end # @see Listener#start def start - Nanoc::NotificationCenter.on(:filtering_started) do |rep, filter_name| + Nanoc::NotificationCenter.on(:filtering_started) do |_rep, filter_name| @times[filter_name] ||= [] @times[filter_name] << { :start => Time.now } end - Nanoc::NotificationCenter.on(:filtering_ended) do |rep, filter_name| + Nanoc::NotificationCenter.on(:filtering_ended) do |_rep, filter_name| @times[filter_name].last[:stop] = Time.now end end # @see Listener#stop def stop print_profiling_feedback super end - protected + protected def print_profiling_feedback # Get max filter length max_filter_name_length = durations_per_filter.keys.map { |k| k.to_s.size }.max return if max_filter_name_length.nil? # Print warning if necessary if @reps.any? { |r| !r.compiled? } $stderr.puts - $stderr.puts 'Warning: profiling information may not be accurate because ' + + $stderr.puts 'Warning: profiling information may not be accurate because ' \ 'some items were not compiled.' end # Print header puts @@ -258,21 +258,21 @@ # Controls garbage collection so that it only occurs once every 20 items class GCController < Listener # @see Listener#enable_for? - def self.enable_for?(command_runner) + def self.enable_for?(_command_runner) !ENV.key?('TRAVIS') end - def initialize(params = {}) + def initialize(_params = {}) @gc_count = 0 end # @see Listener#start def start - Nanoc::NotificationCenter.on(:compilation_started) do |rep| + Nanoc::NotificationCenter.on(:compilation_started) do |_rep| if @gc_count % 20 == 0 GC.enable GC.start GC.disable end @@ -343,11 +343,11 @@ # @see Listener#start def start Nanoc::NotificationCenter.on(:compilation_started) do |rep| @start_times[rep.raw_path] = Time.now end - Nanoc::NotificationCenter.on(:rep_written) do |rep, path, is_created, is_modified| + Nanoc::NotificationCenter.on(:rep_written) do |_rep, path, is_created, is_modified| duration = path && @start_times[path] ? Time.now - @start_times[path] : nil action = case when is_created then :create when is_modified then :update @@ -365,17 +365,17 @@ # @see Listener#stop def stop super @reps.select { |r| !r.compiled? }.each do |rep| - rep.raw_paths.each do |snapshot_name, raw_path| + rep.raw_paths.each do |_snapshot_name, raw_path| log(:low, :skip, raw_path, nil) end end end - private + private def log(level, action, path, duration) Nanoc::CLI::Logger.instance.file(level, action, path, duration) end @@ -401,11 +401,11 @@ time_after = Time.now puts puts "Site compiled in #{format('%.2f', time_after - time_before)}s." end - protected + protected def prune if site.config[:prune][:auto_prune] Nanoc::Extra::Pruner.new(site, :exclude => prune_config_exclude).run end @@ -420,12 +420,12 @@ Nanoc::CLI::Commands::Compile::FileActionPrinter ] end def setup_listeners - @listeners = @listener_classes. - select { |klass| klass.enable_for?(self) }. - map { |klass| klass.new(:reps => reps) } + @listeners = @listener_classes + .select { |klass| klass.enable_for?(self) } + .map { |klass| klass.new(:reps => reps) } @listeners.each { |s| s.start } end def listeners