Module: Bloggit::Checksum
- Defined in:
- lib/bloggit/checksum.rb
Class Method Summary collapse
-
.diff(source = {}, target = {}) ⇒ Object
returns [files_to_upload, files_to_delete].
-
.generate_from(cache_dir) ⇒ Object
Create the checksums…
Class Method Details
.diff(source = {}, target = {}) ⇒ Object
returns [files_to_upload, files_to_delete]
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bloggit/checksum.rb', line 8 def diff(source={}, target={}) # look for differences... src_files = source.fetch('files', {}) tgt_files = target.fetch('files', {}) to_update = []; to_delete = []; to_upload = [] tgt_files.each do |filename, checksum| if src_files.has_key? filename to_update << filename unless src_files[filename] == checksum else to_delete << filename end end to_upload = src_files.keys - tgt_files.keys # returns [files_to_upload, files_to_delete] [[to_upload, to_update].flatten, to_delete] end |
.generate_from(cache_dir) ⇒ Object
Create the checksums…
29 30 31 32 33 34 35 36 |
# File 'lib/bloggit/checksum.rb', line 29 def generate_from(cache_dir) checksums = { 'generated_on'=>Time.now, 'files'=>{} } Find.find( cache_dir ) do |f| next if File.directory?( f ) checksums['files'][f.gsub("#{cache_dir}/", '')] = Digest::MD5.hexdigest( File.read(f) ) end checksums end |