Class: PathHelper

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

Class Method Summary collapse

Class Method Details

.path(sfid) ⇒ Object

This produces a hashed path very similar to mogilefs just without the device id. It also recursively creates the directory inside the backup



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/path_helper.rb', line 4

def self.path(sfid)
  sfid = "#{sfid}"
  length = sfid.length
  if length < 10
    nfid = "0" * (10 - length) + sfid
  else
    nfid = fid
  end
  /(?<b>\d)(?<mmm>\d{3})(?<ttt>\d{3})(?<hto>\d{3})/ =~ nfid

  #create the directory
  directory_path = "#{$backup_path}/#{b}/#{mmm}/#{ttt}"
  FileUtils.mkdir_p(directory_path)

  return "#{directory_path}/#{nfid}.fid"
end