Class: Textus::Infra::FileSystem

Inherits:
Object
  • Object
show all
Includes:
Interface
Defined in:
lib/textus/infra/file_system.rb

Defined Under Namespace

Modules: Interface

Instance Method Summary collapse

Instance Method Details

#copy(source, target) ⇒ Object



35
# File 'lib/textus/infra/file_system.rb', line 35

def copy(source, target) = FileUtils.cp(source, target)

#delete(path) ⇒ Object



27
# File 'lib/textus/infra/file_system.rb', line 27

def delete(path) = File.delete(path)

#dir_empty?(dir) ⇒ Boolean

Returns:

  • (Boolean)


32
# File 'lib/textus/infra/file_system.rb', line 32

def dir_empty?(dir) = Dir.empty?(dir)

#directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


39
# File 'lib/textus/infra/file_system.rb', line 39

def directory?(path) = File.directory?(path)

#etag(path) ⇒ Object



41
42
43
# File 'lib/textus/infra/file_system.rb', line 41

def etag(path)
  Value::Etag.for_file(path)
end

#exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


28
# File 'lib/textus/infra/file_system.rb', line 28

def exists?(path) = File.exist?(path)

#flock_exclusive(path, nonblock: false) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/textus/infra/file_system.rb', line 45

def flock_exclusive(path, nonblock: false)
  File.open(path, File::RDWR | File::CREAT, 0o644) do |f|
    f.close_on_exec = true
    f.flock(nonblock ? File::LOCK_EX | File::LOCK_NB : File::LOCK_EX)
    yield f
  end
end

#glob(pattern) ⇒ Object



33
# File 'lib/textus/infra/file_system.rb', line 33

def glob(pattern) = Dir.glob(pattern)

#identical?(left, right) ⇒ Boolean

Returns:

  • (Boolean)


37
# File 'lib/textus/infra/file_system.rb', line 37

def identical?(left, right) = FileUtils.identical?(left, right)

#mkdir_p(path) ⇒ Object



30
# File 'lib/textus/infra/file_system.rb', line 30

def mkdir_p(path) = FileUtils.mkdir_p(path)

#mtime(path) ⇒ Object



38
# File 'lib/textus/infra/file_system.rb', line 38

def mtime(path) = File.mtime(path)

#mv(from, to) ⇒ Object



34
# File 'lib/textus/infra/file_system.rb', line 34

def mv(from, to) = File.rename(from, to)

#read(path) ⇒ Object



20
# File 'lib/textus/infra/file_system.rb', line 20

def read(path) = File.binread(path)

#rmdir(path) ⇒ Object



31
# File 'lib/textus/infra/file_system.rb', line 31

def rmdir(path) = Dir.rmdir(path)

#size(path) ⇒ Object



29
# File 'lib/textus/infra/file_system.rb', line 29

def size(path) = File.size(path)

#symlink?(path) ⇒ Boolean

Returns:

  • (Boolean)


36
# File 'lib/textus/infra/file_system.rb', line 36

def symlink?(path) = File.symlink?(path)

#write(path, bytes) ⇒ Object



22
23
24
25
# File 'lib/textus/infra/file_system.rb', line 22

def write(path, bytes)
  FileUtils.mkdir_p(File.dirname(path))
  File.binwrite(path, bytes)
end