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

Defined Under Namespace

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

Instance Method Summary collapse

Instance Method Details

#exist?(src) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#ls(dir) ⇒ Object



16
17
18
19
20
21
# File 'lib/etna/filesystem.rb', line 16

def ls(dir)
  raise "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



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

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

#mv(src, dest) ⇒ Object



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

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

#rm_rf(dir) ⇒ Object



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

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

#tmpdirObject



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

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

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



23
24
25
26
# File 'lib/etna/filesystem.rb', line 23

def with_readable(src, opts = 'r', &block)
  raise "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



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

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