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 and verifying content
Class Method Summary collapse
Instance Method Summary collapse
- #orphan_check ⇒ Object
- #restore_to(io) ⇒ Object
- #unique_fingerprint?(key) ⇒ Boolean
- #verified? ⇒ Boolean
Class Method Details
.fresh_entry ⇒ Object
10 11 12 13 14 |
# File 'lib/nearline/file_content.rb', line 10 def self.fresh_entry file_content = FileContent.new file_content.save! file_content end |
Instance Method Details
#orphan_check ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/nearline/file_content.rb', line 16 def orphan_check if (self.archived_files.size == 1) sequences.each do |s| s.destroy s.block.orphan_check end self.destroy end end |
#restore_to(io) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/nearline/file_content.rb', line 33 def restore_to(io) sequences.each do |seq| block = Block.find(seq.block_id) io.write(block.content) end end |
#unique_fingerprint?(key) ⇒ Boolean
26 27 28 29 30 31 |
# File 'lib/nearline/file_content.rb', line 26 def unique_fingerprint?(key) hit = FileContent.connection.select_one( "select id from file_contents where fingerprint='#{key}'" ) return hit.nil? end |
#verified? ⇒ Boolean
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/nearline/file_content.rb', line 40 def verified? if (!self.verified_at.nil?) return true end whole_file_hash = Digest::SHA1.new sequences.each do |seq| block = Block.find(seq.block_id) whole_file_hash.update(block.content) end if fingerprint == whole_file_hash.hexdigest self.verified_at = Time.now self.save! return true end false end |