class GZippedTar::Tar::SplitName

Constants

MAXIMUM_LENGTH
MAXIMUM_NAME_LENGTH
MAXIMUM_PATH_LENGTH

Attributes

file[R]

Public Class Methods

call(file) click to toggle source
# File lib/gzipped_tar/tar/split_name.rb, line 8
def self.call(file)
  new(file).call
end
new(file) click to toggle source
# File lib/gzipped_tar/tar/split_name.rb, line 12
def initialize(file)
  @file = file
end

Public Instance Methods

call() click to toggle source
# File lib/gzipped_tar/tar/split_name.rb, line 16
def call
  return ["", file] unless split?

  raise_if_too_long file,   MAXIMUM_LENGTH,      "path"
  raise_if_too_long name,   MAXIMUM_NAME_LENGTH, "name"
  raise_if_too_long prefix, MAXIMUM_PATH_LENGTH, "base path"

  [prefix, name]
end

Private Instance Methods

last_prefix_index() click to toggle source
# File lib/gzipped_tar/tar/split_name.rb, line 30
def last_prefix_index
  @last_prefix_index ||= begin
    index = parts.length - 2
    index -= 1 while parts[0..index].join("/").bytesize >= MAXIMUM_PATH_LENGTH
    index
  end
end
name() click to toggle source
# File lib/gzipped_tar/tar/split_name.rb, line 38
def name
  parts[(last_prefix_index + 1)..-1].join("/")
end
parts() click to toggle source
# File lib/gzipped_tar/tar/split_name.rb, line 42
def parts
  @parts ||= file.split "/", -1
end
prefix() click to toggle source
# File lib/gzipped_tar/tar/split_name.rb, line 46
def prefix
  parts[0..last_prefix_index].join("/")
end
raise_if_too_long(string, maximum, description) click to toggle source
# File lib/gzipped_tar/tar/split_name.rb, line 50
def raise_if_too_long(string, maximum, description)
  return if string.bytesize <= maximum

  raise GZippedTar::Tar::TooLongFileName,
    "File \"#{string}\" has a too long #{description} (should be " \
    "#{maximum} or less)"
end
split?() click to toggle source

If the file is less than MAXIMUM_NAME_LENGTH, it doesn't need to be split, and the prefix can be blank.

# File lib/gzipped_tar/tar/split_name.rb, line 60
def split?
  file.bytesize > MAXIMUM_NAME_LENGTH
end
too_long?() click to toggle source
# File lib/gzipped_tar/tar/split_name.rb, line 64
def too_long?
  file.bytesize > 256
end