class Burner::Disks::Local

Operations against the local file system.

Public Instance Methods

exist?(path) click to toggle source

Check to see if the passed in path exists within the local file system. It will not make assumptions on what the 'file' is, only that it is recognized by Ruby's File class.

# File lib/burner/disks/local.rb, line 19
def exist?(path)
  File.exist?(path)
end
read(path, binary: false) click to toggle source

Open and read the contents of a local file. If binary is passed in as true then the file will be opened in binary mode.

# File lib/burner/disks/local.rb, line 25
def read(path, binary: false)
  File.open(path, read_mode(binary), &:read)
end
write(path, data, binary: false) click to toggle source

Open and write the specified data to a local file. If binary is passed in as true then the file will be opened in binary mode. It is important to note that if the file's directory structure will be automatically created if it does not exist.

# File lib/burner/disks/local.rb, line 32
def write(path, data, binary: false)
  ensure_directory_exists(path)

  File.open(path, write_mode(binary)) { |io| io.write(data) }

  path
end

Private Instance Methods

ensure_directory_exists(path) click to toggle source
# File lib/burner/disks/local.rb, line 42
def ensure_directory_exists(path)
  dirname = File.dirname(path)

  return if File.exist?(dirname)

  FileUtils.mkdir_p(dirname)

  nil
end
read_mode(binary) click to toggle source
# File lib/burner/disks/local.rb, line 56
def read_mode(binary)
  binary ? 'rb' : 'r'
end
write_mode(binary) click to toggle source
# File lib/burner/disks/local.rb, line 52
def write_mode(binary)
  binary ? 'wb' : 'w'
end