From 0f74db413110ae7cb435bbd2d7f21a2918dd9cfe Mon Sep 17 00:00:00 2001 From: Anatoliy Yastreb Date: Thu, 16 Jun 2016 23:12:01 +0300 Subject: [PATCH] rubocop: move mtimes cache hash to class variable --- lib/jekyll/static_file.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/jekyll/static_file.rb b/lib/jekyll/static_file.rb index 5471c2a9..0f8544ee 100644 --- a/lib/jekyll/static_file.rb +++ b/lib/jekyll/static_file.rb @@ -2,6 +2,17 @@ module Jekyll class StaticFile attr_reader :relative_path, :extname + class << self + # The cache of last modification times [path] -> mtime. + def mtimes + @mtimes ||= {} + end + + def reset_cache + @mtimes = nil + end + end + # Initialize a new StaticFile. # # site - The Site. @@ -17,8 +28,6 @@ module Jekyll @collection = collection @relative_path = File.join(*[@dir, @name].compact) @extname = File.extname(@name) - # The cache of last modification times [path] -> mtime. - @mtimes = {} end # rubocop: enable ParameterLists @@ -57,7 +66,7 @@ module Jekyll # # Returns true if modified since last write. def modified? - @mtimes[path] != mtime + self.class.mtimes[path] != mtime end # Whether to write the file to the filesystem @@ -77,12 +86,11 @@ module Jekyll dest_path = destination(dest) return false if File.exist?(dest_path) && !modified? - @mtimes[path] = mtime + self.class.mtimes[path] = mtime FileUtils.mkdir_p(File.dirname(dest_path)) FileUtils.rm(dest_path) if File.exist?(dest_path) copy_file(dest_path) - File.utime(@mtimes[path], @mtimes[path], dest_path) true end @@ -138,6 +146,7 @@ module Jekyll else FileUtils.copy_entry(path, dest_path) end + File.utime(self.class.mtimes[path], self.class.mtimes[path], dest_path) end end end