Class: SafeDb::FileTree

Inherits:
Object
  • Object
show all
Defined in:
lib/model/file_tree.rb

Overview

This class knows the location of the main indices and crypt files and folders both for the master and branch lines.

More importantly, it knows where the master crypts and indices are given a book id, and also the branch crypts and indices, given a branch id.

Class Method Summary collapse

Class Method Details

.branch_crypts_filepath(book_id, branch_id, content_id) ⇒ Object



34
35
36
# File 'lib/model/file_tree.rb', line 34

def self.branch_crypts_filepath( book_id, branch_id, content_id )
  return File.join( branch_crypts_folder( book_id, branch_id ), "safedb.chapter.#{content_id}.txt" )
end

.branch_crypts_folder(book_id, branch_id) ⇒ Object



39
40
41
# File 'lib/model/file_tree.rb', line 39

def self.branch_crypts_folder( book_id, branch_id )
  return File.join( Indices::BRANCH_CRYPTS_FOLDER_PATH, "safedb-branch-#{book_id}-#{branch_id}" )
end

.branch_indices_filepath(branch_id) ⇒ File

Get the path to the branch indices file for the branch ID specified in the parameter.

Parameters:

  • branch_id (String)

    the identifier of the branch in question

Returns:

  • (File)

    path to the branch indices file for the given branch



48
49
50
# File 'lib/model/file_tree.rb', line 48

def self.branch_indices_filepath( branch_id )
  return File.join( Indices::BRANCH_INDICES_FOLDER_PATH, "safedb-indices-#{branch_id}.ini" )
end

.master_crypts_filepath(book_id, content_id) ⇒ File

Find the path to the file that contains the book index within the master (not branch) line. We need the book identifier and the file’s content identifier to derive the path.

Parameters:

  • book_id (String)

    the identifier of the book in question

  • content_id (String)

    the identifier of the chapter content

Returns:

  • (File)

    path to the crypted content index file for book



20
21
22
# File 'lib/model/file_tree.rb', line 20

def self.master_crypts_filepath( book_id, content_id )
  return File.join( master_crypts_folder( book_id ), "safedb.chapter.#{content_id}.txt" )
end

.master_crypts_folder(book_id) ⇒ File

Get the path to the folder that holds the master crypts for the book ID specified in the parameter.

Parameters:

  • book_id (String)

    the identifier of the book in question

Returns:

  • (File)

    path to the master crypts folder for the book



29
30
31
# File 'lib/model/file_tree.rb', line 29

def self.master_crypts_folder( book_id )
  return File.join( Indices::MASTER_CRYPTS_FOLDER_PATH, "safedb.book.#{book_id}" )
end