Class: Burner::Disks::Local

Inherits:
Object
  • Object
show all
Defined in:
lib/burner/disks/local.rb

Overview

Operations against the local file system.

Instance Method Summary collapse

Instance Method Details

#exist?(path) ⇒ Boolean

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.

Returns:

  • (Boolean)


19
20
21
# File 'lib/burner/disks/local.rb', line 19

def exist?(path)
  File.exist?(path)
end

#read(path, binary: false) ⇒ Object

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.



25
26
27
# 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) ⇒ Object

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.



32
33
34
35
36
37
38
# 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