Class: Nearline::Models::FileContent
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Nearline::Models::FileContent
- Defined in:
- lib/nearline/file_content.rb
Overview
Has the responsibility of identifying, restoring and verifying content
Instance Method Summary collapse
- #orphan_check ⇒ Object
- #restore_to(io) ⇒ Object
- #unique_fingerprint?(key) ⇒ Boolean
- #verified? ⇒ Boolean
Instance Method Details
#orphan_check ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/nearline/file_content.rb', line 10 def orphan_check if (self.archived_files.size < 2) sequences.each do |s| s.destroy end self.destroy end end |
#restore_to(io) ⇒ Object
37 38 39 |
# File 'lib/nearline/file_content.rb', line 37 def restore_to(io) each_sequence { |block| io.write(block.content) } end |
#unique_fingerprint?(key) ⇒ Boolean
19 20 21 22 23 24 |
# File 'lib/nearline/file_content.rb', line 19 def unique_fingerprint?(key) hit = FileContent.connection.select_one( "select id from file_contents where fingerprint='#{key}'" ) return hit.nil? end |
#verified? ⇒ Boolean
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/nearline/file_content.rb', line 41 def verified? return true if (!self.verified_at.nil?) whole_file_hash = Digest::SHA1.new each_sequence { |block| whole_file_hash.update(block.content) } if fingerprint == whole_file_hash.hexdigest self.verified_at = Time.now self.save! return true end false end |