Class: BFS::Bucket::FS
Overview
FS buckets are operating on the file system
Instance Attribute Summary
Attributes inherited from Abstract
Instance Method Summary collapse
-
#cp(src, dst, **_opts) ⇒ Object
Copies a file.
-
#create(path, encoding: self.encoding, perm: self.perm, **_opts, &block) ⇒ Object
Creates a new file and opens it for writing.
-
#glob(pattern = '**/*', **_opts) ⇒ Object
Iterates over the contents of a bucket using a glob pattern.
-
#info(path, **_opts) ⇒ Object
Info returns the info for a single file.
-
#initialize(root, **opts) ⇒ FS
constructor
A new instance of FS.
-
#ls(pattern = '**/*', **_opts) ⇒ Object
Lists the contents of a bucket using a glob pattern.
-
#mv(src, dst, **_opts) ⇒ Object
Moves a file.
-
#open(path, **opts, &block) ⇒ Object
Opens an existing file for reading.
-
#rm(path, **_opts) ⇒ Object
Deletes a file.
Methods inherited from Abstract
Constructor Details
Instance Method Details
#cp(src, dst, **_opts) ⇒ Object
Copies a file.
86 87 88 89 90 91 92 93 |
# File 'lib/bfs/bucket/fs.rb', line 86 def cp(src, dst, **_opts) full_src = @root.join(norm_path(src)) full_dst = @root.join(norm_path(dst)) FileUtils.mkdir_p full_dst.dirname.to_s FileUtils.cp full_src.to_s, full_dst.to_s rescue Errno::ENOENT raise BFS::FileNotFound, norm_path(src) end |
#create(path, encoding: self.encoding, perm: self.perm, **_opts, &block) ⇒ Object
Creates a new file and opens it for writing
52 53 54 55 56 57 58 59 |
# File 'lib/bfs/bucket/fs.rb', line 52 def create(path, encoding: self.encoding, perm: self.perm, **_opts, &block) full = @root.join(norm_path(path)) FileUtils.mkdir_p(full.dirname.to_s) BFS::Writer.new(full, encoding: encoding, perm: perm) do |temp| FileUtils.mv temp, full.to_s end.perform(&block) end |
#glob(pattern = '**/*', **_opts) ⇒ Object
Iterates over the contents of a bucket using a glob pattern
26 27 28 29 30 31 32 |
# File 'lib/bfs/bucket/fs.rb', line 26 def glob(pattern = '**/*', **_opts) Enumerator.new do |acc| walk(pattern) do |path, stat| acc << file_info(path, stat) end end end |
#info(path, **_opts) ⇒ Object
Info returns the info for a single file
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bfs/bucket/fs.rb', line 35 def info(path, **_opts) norm = norm_path(path) pn = @root.join(norm) stat = pn.stat raise BFS::FileNotFound, path unless stat.file? file_info(norm, stat) rescue Errno::ENOENT raise BFS::FileNotFound, path end |
#ls(pattern = '**/*', **_opts) ⇒ Object
Lists the contents of a bucket using a glob pattern
17 18 19 20 21 22 23 |
# File 'lib/bfs/bucket/fs.rb', line 17 def ls(pattern = '**/*', **_opts) Enumerator.new do |acc| walk(pattern) do |path, _| acc << path end end end |
#mv(src, dst, **_opts) ⇒ Object
Moves a file.
99 100 101 102 103 104 105 106 |
# File 'lib/bfs/bucket/fs.rb', line 99 def mv(src, dst, **_opts) full_src = @root.join(norm_path(src)) full_dst = @root.join(norm_path(dst)) FileUtils.mkdir_p full_dst.dirname.to_s FileUtils.mv full_src.to_s, full_dst.to_s rescue Errno::ENOENT raise BFS::FileNotFound, norm_path(src) end |
#open(path, **opts, &block) ⇒ Object
Opens an existing file for reading
66 67 68 69 70 71 72 |
# File 'lib/bfs/bucket/fs.rb', line 66 def open(path, **opts, &block) path = norm_path(path) full = @root.join(path) full.open(**opts, &block) rescue Errno::ENOENT raise BFS::FileNotFound, path end |
#rm(path, **_opts) ⇒ Object
Deletes a file.
77 78 79 80 |
# File 'lib/bfs/bucket/fs.rb', line 77 def rm(path, **_opts) full = @root.join(norm_path(path)) FileUtils.rm_f full.to_s end |