Class: EasyHtmlGenerator::Checksum
- Inherits:
-
Object
- Object
- EasyHtmlGenerator::Checksum
- Defined in:
- lib/easy_html_generator/checksum.rb
Overview
this class handles file checksums
Class Method Summary collapse
- .array_checksum(files) ⇒ Object
- .build_key(file, context = '') ⇒ Object
- .checksum(input) ⇒ Object
- .file_changed?(file, context = '') ⇒ Boolean
- .file_checksum(file) ⇒ Object
- .folder_changed?(folder, context = '') ⇒ Boolean
- .invalidate_all ⇒ Object
- .invalidate_file(file, context = '') ⇒ Object
- .store_file(file, context = '') ⇒ Object
Class Method Details
.array_checksum(files) ⇒ Object
18 19 20 21 22 |
# File 'lib/easy_html_generator/checksum.rb', line 18 def self.array_checksum(files) tmp = '' files.each { |file| tmp += File.read(file) if File.file? file } checksum(tmp) end |
.build_key(file, context = '') ⇒ Object
56 57 58 |
# File 'lib/easy_html_generator/checksum.rb', line 56 def self.build_key(file, context = '') "#{context}.#{file}" end |
.checksum(input) ⇒ Object
8 9 10 |
# File 'lib/easy_html_generator/checksum.rb', line 8 def self.checksum(input) Digest::MD5.hexdigest(input) end |
.file_changed?(file, context = '') ⇒ Boolean
24 25 26 27 28 29 30 |
# File 'lib/easy_html_generator/checksum.rb', line 24 def self.file_changed?(file, context = '') key = build_key(file, context) return true unless @file_checksums.key? key @file_checksums[key] != file_checksum(file) end |
.file_checksum(file) ⇒ Object
12 13 14 15 16 |
# File 'lib/easy_html_generator/checksum.rb', line 12 def self.file_checksum(file) return array_checksum(file) if file.is_a? Array return array_checksum(Dir["#{folder}/**/*"]) if File.directory? file checksum(File.read(file)) end |
.folder_changed?(folder, context = '') ⇒ Boolean
32 33 34 35 36 37 38 |
# File 'lib/easy_html_generator/checksum.rb', line 32 def self.folder_changed?(folder, context = '') key = build_key(folder, context) return true unless @file_checksums.key? key @file_checksums[key] != folder_checksum(folder) end |
.invalidate_all ⇒ Object
52 53 54 |
# File 'lib/easy_html_generator/checksum.rb', line 52 def self.invalidate_all() @file_checksums = {} end |
.invalidate_file(file, context = '') ⇒ Object
46 47 48 49 50 |
# File 'lib/easy_html_generator/checksum.rb', line 46 def self.invalidate_file(file, context = '') key = build_key(file, context) @file_checksums.delete(key) end |
.store_file(file, context = '') ⇒ Object
40 41 42 43 44 |
# File 'lib/easy_html_generator/checksum.rb', line 40 def self.store_file(file, context = '') key = build_key(file, context) @file_checksums[key] = file_checksum(file) end |