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
44
45
46
47
|
# File 'lib/etna/filesystem.rb', line 44
def exist?(src)
raise "exist? not supported by #{self.class.name}" unless self.class == Filesystem
::File.exist?(src)
end
|
#ls(dir) ⇒ Object
17
18
19
20
21
22
|
# File 'lib/etna/filesystem.rb', line 17
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
29
30
31
32
|
# File 'lib/etna/filesystem.rb', line 29
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
49
50
51
52
|
# File 'lib/etna/filesystem.rb', line 49
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
34
35
36
37
|
# File 'lib/etna/filesystem.rb', line 34
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
54
55
56
57
|
# File 'lib/etna/filesystem.rb', line 54
def stat(src)
raise "stat not supported by #{self.class.name}" unless self.class == Filesystem
::File.stat(src)
end
|
#tmpdir ⇒ Object
39
40
41
42
|
# File 'lib/etna/filesystem.rb', line 39
def tmpdir
raise "tmpdir not supported by #{self.class.name}" unless self.class == Filesystem
::Dir.mktmpdir
end
|
#with_readable(src, opts = 'r', &block) ⇒ Object
24
25
26
27
|
# File 'lib/etna/filesystem.rb', line 24
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
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
|