Class: ContentfulMiddleman::VersionHash
- Inherits:
-
Object
- Object
- ContentfulMiddleman::VersionHash
- Defined in:
- lib/contentful_middleman/version_hash.rb
Class Method Summary collapse
- .read_for_space(space_name) ⇒ Object
- .source_root=(source_root) ⇒ Object
- .write_for_space_with_entries(space_name, entries) ⇒ Object
Class Method Details
.read_for_space(space_name) ⇒ Object
8 9 10 11 |
# File 'lib/contentful_middleman/version_hash.rb', line 8 def read_for_space(space_name) hashfilename_for_space = hashfilename(space_name) ::File.read(hashfilename_for_space) if File.exist? hashfilename_for_space end |
.source_root=(source_root) ⇒ Object
4 5 6 |
# File 'lib/contentful_middleman/version_hash.rb', line 4 def source_root=(source_root) @source_root = source_root end |
.write_for_space_with_entries(space_name, entries) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/contentful_middleman/version_hash.rb', line 13 def write_for_space_with_entries(space_name, entries) sorted_entries = entries.sort {|a, b| a.id <=> b.id} ids_and_revisions_string = sorted_entries.map {|e| "#{e.id}#{e.updated_at}"}.join entries_hash = Digest::SHA1.hexdigest( ids_and_revisions_string ) File.open(hashfilename(space_name), 'w') { |file| file.write(entries_hash) } entries_hash end |