Class: Etna::Filesystem
- Inherits:
-
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.
Defined Under Namespace
Modules: WithPipeConsumer
Classes: AsperaCliFilesystem, EmptyIO, GeneAsperaCliFilesystem, Metis, Mock, SftpFilesystem
Instance Method Summary
collapse
Instance Method Details
#exist?(src) ⇒ Boolean
45
46
47
48
|
# File 'lib/etna/filesystem.rb', line 45
def exist?(src)
raise "exist? not supported by #{self.class.name}" unless self.class == Filesystem
::File.exist?(src)
end
|
#ls(dir) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/etna/filesystem.rb', line 18
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
30
31
32
33
|
# File 'lib/etna/filesystem.rb', line 30
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
50
51
52
53
|
# File 'lib/etna/filesystem.rb', line 50
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
35
36
37
38
|
# File 'lib/etna/filesystem.rb', line 35
def rm_rf(dir)
raise "rm_rf not supported by #{self.class.name}" unless self.class == Filesystem
::FileUtils.rm_rf(dir)
end
|
#stat(src) ⇒ Object
55
56
57
58
|
# File 'lib/etna/filesystem.rb', line 55
def stat(src)
raise "stat not supported by #{self.class.name}" unless self.class == Filesystem
::File.stat(src)
end
|
#tmpdir ⇒ Object
40
41
42
43
|
# File 'lib/etna/filesystem.rb', line 40
def tmpdir
raise "tmpdir not supported by #{self.class.name}" unless self.class == Filesystem
::Dir.mktmpdir
end
|
#with_readable(src, opts = 'r', &block) ⇒ Object
25
26
27
28
|
# File 'lib/etna/filesystem.rb', line 25
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
13
14
15
16
|
# File 'lib/etna/filesystem.rb', line 13
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
|