Class: Etna::Filesystem

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

Overview

A class that encapsulates opening / reading file system entries that abstracts normal file access in order to make stubbing, substituting, and testing easier.

Direct Known Subclasses

AsperaCliFilesystem, Metis, Mock, SftpFilesystem

Defined Under Namespace

Modules: WithPipeConsumer Classes: AsperaCliFilesystem, EmptyIO, Error, GeneAsperaCliFilesystem, Metis, Mock, SftpFilesystem

Instance Method Summary collapse

Instance Method Details

#exist?(src) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



47
48
49
50
# File 'lib/etna/filesystem.rb', line 47

def exist?(src)
  raise Etna::Filesystem::Error, "exist? not supported by #{self.class.name}" unless self.class == Filesystem
  ::File.exist?(src)
end

#ls(dir) ⇒ Object



20
21
22
23
24
25
# File 'lib/etna/filesystem.rb', line 20

def ls(dir)
  raise Etna::Filesystem::Error, "ls not supported by #{self.class.name}" unless self.class == Filesystem
  ::Dir.entries(dir).select { |p| !p.start_with?('.') }.map do |path|
    ::File.file?(::File.join(dir, path)) ? [:file, path] : [:dir, path]
  end
end

#mkdir_p(dir) ⇒ Object



32
33
34
35
# File 'lib/etna/filesystem.rb', line 32

def mkdir_p(dir)
  raise Etna::Filesystem::Error, "mkdir_p not supported by #{self.class.name}" unless self.class == Filesystem
  ::FileUtils.mkdir_p(dir)
end

#mv(src, dest) ⇒ Object



52
53
54
55
# File 'lib/etna/filesystem.rb', line 52

def mv(src, dest)
  raise Etna::Filesystem::Error, "mv not supported by #{self.class.name}" unless self.class == Filesystem
  ::FileUtils.mv(src, dest)
end

#rm_rf(dir) ⇒ Object



37
38
39
40
# File 'lib/etna/filesystem.rb', line 37

def rm_rf(dir)
  raise Etna::Filesystem::Error, "rm_rf not supported by #{self.class.name}" unless self.class == Filesystem
  ::FileUtils.rm_rf(dir)
end

#stat(src) ⇒ Object



57
58
59
60
# File 'lib/etna/filesystem.rb', line 57

def stat(src)
  raise Etna::Filesystem::Error, "stat not supported by #{self.class.name}" unless self.class == Filesystem
  ::File.stat(src)
end

#tmpdirObject



42
43
44
45
# File 'lib/etna/filesystem.rb', line 42

def tmpdir
  raise Etna::Filesystem::Error, "tmpdir not supported by #{self.class.name}" unless self.class == Filesystem
  ::Dir.mktmpdir
end

#with_readable(src, opts = 'r', &block) ⇒ Object



27
28
29
30
# File 'lib/etna/filesystem.rb', line 27

def with_readable(src, opts = 'r', &block)
  raise Etna::Filesystem::Error, "with_readable not supported by #{self.class.name}" unless self.class == Filesystem
  ::File.open(src, opts, &block)
end

#with_writeable(dest, opts = 'w', size_hint: nil, &block) ⇒ Object



12
13
14
15
# File 'lib/etna/filesystem.rb', line 12

def with_writeable(dest, opts = 'w', size_hint: nil, &block)
  raise "with_writeable not supported by #{self.class.name}" unless self.class == Filesystem
  ::File.open(dest, opts, &block)
end