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
- .build_key(file, context = '') ⇒ Object
- .checksum(input) ⇒ Object
- .file_changed?(file, context = '') ⇒ Boolean
- .file_checksum(file) ⇒ Object
- .invalidate_file(file, context = '') ⇒ Object
- .store_file(file, context = '') ⇒ Object
Class Method Details
.build_key(file, context = '') ⇒ Object
36 37 38 |
# File 'lib/easy_html_generator/checksum.rb', line 36 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
16 17 18 19 20 21 22 |
# File 'lib/easy_html_generator/checksum.rb', line 16 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 |
# File 'lib/easy_html_generator/checksum.rb', line 12 def self.file_checksum(file) checksum(File.read(file)) end |
.invalidate_file(file, context = '') ⇒ Object
30 31 32 33 34 |
# File 'lib/easy_html_generator/checksum.rb', line 30 def self.invalidate_file(file, context = '') key = build_key(file, context) @file_checksums.delete(key) end |
.store_file(file, context = '') ⇒ Object
24 25 26 27 28 |
# File 'lib/easy_html_generator/checksum.rb', line 24 def self.store_file(file, context = '') key = build_key(file, context) @file_checksums[key] = file_checksum(file) end |