Class: Nearline::Models::FileContent

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/nearline/file_content.rb

Overview

Has the responsibility of identifying, restoring and verifying content

Instance Method Summary collapse

Instance Method Details

#orphan_checkObject



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

Returns:

  • (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

Returns:

  • (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