bfs 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 139902b9141990300b11bbc8dbaf74d98e5a2d5c94bd0d908a4186a0cbe90e86
4
- data.tar.gz: ca0f8d4823962e60c94933c9420772ca272eb1b37a986a01f6a961107d30f66a
3
+ metadata.gz: 13963edd5c68d92d4f5ce4ef5c3f3ef0131ddb318b36f4d7114e3e49e4a16a3b
4
+ data.tar.gz: b805a46a30c795dd6dc9c8761876a4af5bd73dcc117a2f7c76c8acea7a957ed9
5
5
  SHA512:
6
- metadata.gz: 231594d9d7c86d32fef8c967ac4bf5e2184b219e1a495a04372e86fb4114c2391511c5f752c8f8af4238cdccb6bc8d7f51f9f98d4fe9e42bed61796b1cafb210
7
- data.tar.gz: a87d958cc0aa9303f63cf786b2d995bd348db5c248f7802f39ac71a773ef93afe2f747b988b585219720bf826a7624351a07406e3cd3600df1d79fe1c04e0e7f
6
+ metadata.gz: cd9c768fed6d9efa36379f9151c4066931cc92267d032b1b0e920c7150b7db108acb739ecd46b5e8c5853b0ff090767b259e35b0d98b1707fa41491c3eb9dd9e
7
+ data.tar.gz: 123205693490cd8ee1394be308f28944d84e10098dae690cd54d3bf073710d2f538d397960b19d4d0c33ec271bdbbea3df796bd086733d57f9d28db2c52e7bd6
@@ -15,5 +15,5 @@ Gem::Specification.new do |s|
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- spec/*`.split("\n")
17
17
  s.require_paths = ['lib']
18
- s.required_ruby_version = '>= 2.4.0'
18
+ s.required_ruby_version = '>= 2.5.0'
19
19
  end
@@ -12,40 +12,40 @@ module BFS
12
12
  end
13
13
 
14
14
  # Info returns the blob info.
15
- def info(opts={})
16
- @bucket.info(path, opts)
15
+ def info(**opts)
16
+ @bucket.info(path, **opts)
17
17
  end
18
18
 
19
19
  # Creates the blob and opens it for writing.
20
- def create(opts={}, &block)
21
- @bucket.create(path, opts, &block)
20
+ def create(**opts, &block)
21
+ @bucket.create(path, **opts, &block)
22
22
  end
23
23
 
24
24
  # Opens the blob for reading.
25
25
  # May raise BFS::FileNotFound.
26
- def open(opts={}, &block)
27
- @bucket.open(path, opts, &block)
26
+ def open(**opts, &block)
27
+ @bucket.open(path, **opts, &block)
28
28
  end
29
29
 
30
30
  # Deletes the blob.
31
- def rm(opts={})
32
- @bucket.rm(path, opts)
31
+ def rm(**opts)
32
+ @bucket.rm(path, **opts)
33
33
  end
34
34
 
35
35
  # Shortcut method to read the contents of the blob.
36
- def read(opts={})
37
- open(opts, &:read)
36
+ def read(**opts)
37
+ open(**opts, &:read)
38
38
  end
39
39
 
40
40
  # Shortcut method to write data to blob.
41
- def write(data, opts={})
42
- create(opts) {|f| f.write data }
41
+ def write(data, **opts)
42
+ create(**opts) {|f| f.write data }
43
43
  end
44
44
 
45
45
  # Moves blob to dst.
46
- def mv(dst, opts={})
46
+ def mv(dst, **opts)
47
47
  dst = BFS.norm_path(dst)
48
- @bucket.mv(path, dst, opts)
48
+ @bucket.mv(path, dst, **opts)
49
49
  @path = dst
50
50
  end
51
51
 
@@ -6,33 +6,33 @@ module BFS
6
6
  # Initializes a new bucket
7
7
  # @param [Hash] opts options
8
8
  # @option opts [String] :encoding Custom encoding. Default: Encoding.default_external.
9
- def initialize(opts={})
9
+ def initialize(**opts)
10
10
  @encoding = opts.delete(:encoding) || Encoding.default_external
11
11
  end
12
12
 
13
13
  # Lists the contents of a bucket using a glob pattern
14
- def ls(_pattern='**', _opts={})
14
+ def ls(_pattern = '**', **_opts)
15
15
  raise 'not implemented'
16
16
  end
17
17
 
18
18
  # Info returns the info for a single file
19
- def info(_path, _opts={})
19
+ def info(_path, **_opts)
20
20
  raise 'not implemented'
21
21
  end
22
22
 
23
23
  # Creates a new file and opens it for writing
24
- def create(_path, _opts={})
24
+ def create(_path, **_opts)
25
25
  raise 'not implemented'
26
26
  end
27
27
 
28
28
  # Opens an existing file for reading
29
29
  # May raise BFS::FileNotFound
30
- def open(_path, _opts={})
30
+ def open(_path, **_opts)
31
31
  raise 'not implemented'
32
32
  end
33
33
 
34
34
  # Deletes a file.
35
- def rm(_path, _opts={})
35
+ def rm(_path, **_opts)
36
36
  raise 'not implemented'
37
37
  end
38
38
 
@@ -40,8 +40,8 @@ module BFS
40
40
  #
41
41
  # @param [String] path The path to read from.
42
42
  # @param [Hash] opts Additional options, see #open.
43
- def read(path, opts={})
44
- open(path, opts, &:read)
43
+ def read(path, **opts)
44
+ open(path, **opts, &:read)
45
45
  end
46
46
 
47
47
  # Shortcut method to write data to path
@@ -49,17 +49,17 @@ module BFS
49
49
  # @param [String] path The path to write to.
50
50
  # @param [String] data The data to write.
51
51
  # @param [Hash] opts Additional options, see #create.
52
- def write(path, data, opts={})
53
- create(path, opts) {|f| f.write data }
52
+ def write(path, data, **opts)
53
+ create(path, **opts) {|f| f.write data }
54
54
  end
55
55
 
56
56
  # Copies src to dst
57
57
  #
58
58
  # @param [String] src The source path.
59
59
  # @param [String] dst The destination path.
60
- def cp(src, dst, opts={})
61
- open(src, opts) do |r|
62
- create(dst, opts) do |w|
60
+ def cp(src, dst, **opts)
61
+ open(src, **opts) do |r|
62
+ create(dst, **opts) do |w|
63
63
  IO.copy_stream(r, w)
64
64
  end
65
65
  end
@@ -69,7 +69,7 @@ module BFS
69
69
  #
70
70
  # @param [String] src The source path.
71
71
  # @param [String] dst The destination path.
72
- def mv(src, dst, _opts={})
72
+ def mv(src, dst, **_opts)
73
73
  cp(src, dst)
74
74
  rm(src)
75
75
  end
@@ -6,15 +6,15 @@ module BFS
6
6
  module Bucket
7
7
  # FS buckets are operating on the file system
8
8
  class FS < Abstract
9
- def initialize(root, opts={})
10
- super(opts.dup)
9
+ def initialize(root, **opts)
10
+ super(**opts.dup)
11
11
 
12
12
  @root = Pathname.new(root.to_s)
13
13
  @prefix = "#{@root.to_s.chomp('/')}/"
14
14
  end
15
15
 
16
16
  # Lists the contents of a bucket using a glob pattern
17
- def ls(pattern='**/*', _opts={})
17
+ def ls(pattern = '**/*', **_opts)
18
18
  Enumerator.new do |y|
19
19
  Pathname.glob(@root.join(pattern)) do |pname|
20
20
  y << trim_prefix(pname.to_s) if pname.file?
@@ -23,7 +23,7 @@ module BFS
23
23
  end
24
24
 
25
25
  # Info returns the info for a single file
26
- def info(path, _opts={})
26
+ def info(path, **_opts)
27
27
  full = @root.join(norm_path(path))
28
28
  path = trim_prefix(full.to_s)
29
29
  BFS::FileInfo.new(path, full.size, full.mtime, nil, {})
@@ -36,12 +36,14 @@ module BFS
36
36
  # @param [String] path The creation path.
37
37
  # @param [Hash] opts Additional options.
38
38
  # @option opts [String] :encoding Custom encoding.
39
- def create(path, opts={}, &block)
39
+ # @option opts [Integer] :perm Custom file permission, default: 0600.
40
+ def create(path, **opts, &block)
40
41
  full = @root.join(norm_path(path))
41
42
  FileUtils.mkdir_p(full.dirname.to_s)
42
43
 
44
+ perm = opts[:perm]
43
45
  enc = opts[:encoding] || @encoding
44
- temp = BFS::TempWriter.new(full, encoding: enc) {|t| FileUtils.mv t, full.to_s }
46
+ temp = BFS::TempWriter.new(full, perm: perm, encoding: enc) {|t| FileUtils.mv t, full.to_s }
45
47
  return temp unless block
46
48
 
47
49
  begin
@@ -56,10 +58,10 @@ module BFS
56
58
  # @param [String] path The path to open.
57
59
  # @param [Hash] opts Additional options.
58
60
  # @option opts [String] :encoding Custom encoding.
59
- def open(path, opts={}, &block)
61
+ def open(path, **opts, &block)
60
62
  path = norm_path(path)
61
63
  full = @root.join(path)
62
- full.open(opts, &block)
64
+ full.open(**opts, &block)
63
65
  rescue Errno::ENOENT
64
66
  raise BFS::FileNotFound, path
65
67
  end
@@ -67,7 +69,7 @@ module BFS
67
69
  # Deletes a file.
68
70
  #
69
71
  # @param [String] path The path to delete.
70
- def rm(path, _opts={})
72
+ def rm(path, **_opts)
71
73
  full = @root.join(norm_path(path))
72
74
  FileUtils.rm_f full.to_s
73
75
  end
@@ -76,7 +78,7 @@ module BFS
76
78
  #
77
79
  # @param [String] src The source path.
78
80
  # @param [String] dst The destination path.
79
- def cp(src, dst, _opts={})
81
+ def cp(src, dst, **_opts)
80
82
  full_src = @root.join(norm_path(src))
81
83
  full_dst = @root.join(norm_path(dst))
82
84
  FileUtils.mkdir_p full_dst.dirname.to_s
@@ -89,7 +91,7 @@ module BFS
89
91
  #
90
92
  # @param [String] src The source path.
91
93
  # @param [String] dst The destination path.
92
- def mv(src, dst, _opts={})
94
+ def mv(src, dst, **_opts)
93
95
  full_src = @root.join(norm_path(src))
94
96
  full_dst = @root.join(norm_path(dst))
95
97
  FileUtils.mkdir_p full_dst.dirname.to_s
@@ -7,8 +7,8 @@ module BFS
7
7
  class InMem < Abstract
8
8
  Entry = Struct.new(:io, :mtime, :content_type, :metadata)
9
9
 
10
- def initialize(opts={})
11
- super(opts.dup)
10
+ def initialize(**opts)
11
+ super(**opts.dup)
12
12
  @files = {}
13
13
  end
14
14
 
@@ -18,7 +18,7 @@ module BFS
18
18
  end
19
19
 
20
20
  # Lists the contents of a bucket using a glob pattern
21
- def ls(pattern='**/*', _opts={})
21
+ def ls(pattern = '**/*', **_opts)
22
22
  Enumerator.new do |y|
23
23
  @files.each_key do |key|
24
24
  y << key if File.fnmatch?(pattern, key, File::FNM_PATHNAME)
@@ -27,7 +27,7 @@ module BFS
27
27
  end
28
28
 
29
29
  # Info returns the file info
30
- def info(path, _opts={})
30
+ def info(path, **_opts)
31
31
  path = norm_path(path)
32
32
  raise BFS::FileNotFound, path unless @files.key?(path)
33
33
 
@@ -42,7 +42,7 @@ module BFS
42
42
  # @option opts [String] :encoding Custom encoding.
43
43
  # @option opts [String] :content_type Custom content type.
44
44
  # @option opts [Hash] :metadata Metadata key-value pairs.
45
- def create(path, opts={}, &block)
45
+ def create(path, **opts, &block)
46
46
  io = StringIO.new
47
47
  io.set_encoding(opts[:encoding] || @encoding)
48
48
 
@@ -57,7 +57,7 @@ module BFS
57
57
  end
58
58
 
59
59
  # Opens an existing file for reading
60
- def open(path, _opts={}, &block)
60
+ def open(path, **_opts, &block)
61
61
  path = norm_path(path)
62
62
  raise BFS::FileNotFound, path unless @files.key?(path)
63
63
 
@@ -73,7 +73,7 @@ module BFS
73
73
  end
74
74
 
75
75
  # Deletes a file.
76
- def rm(path, _opts={})
76
+ def rm(path, **_opts)
77
77
  @files.delete(norm_path(path))
78
78
  end
79
79
  end
@@ -3,9 +3,10 @@ require 'delegate'
3
3
 
4
4
  module BFS
5
5
  class TempWriter < DelegateClass(::Tempfile)
6
- def initialize(name, opts={}, &closer)
6
+ def initialize(name, tempdir: nil, perm: nil, **opts, &closer)
7
7
  @closer = closer
8
- @tempfile = ::Tempfile.new(File.basename(name.to_s), opts)
8
+ @tempfile = ::Tempfile.new(File.basename(name.to_s), tempdir, **opts)
9
+ @tempfile.chmod(perm) if perm
9
10
  super @tempfile
10
11
  end
11
12
 
@@ -6,8 +6,8 @@ RSpec.describe BFS::Bucket::FS do
6
6
  subject { described_class.new(tmpdir) }
7
7
 
8
8
  it_behaves_like 'a bucket',
9
- content_type: false,
10
- metadata: false
9
+ content_type: false,
10
+ metadata: false
11
11
 
12
12
  it 'should resolve from URL' do
13
13
  File.open(File.join(tmpdir, 'test.txt'), 'wb') {|f| f.write 'TESTDATA' }
@@ -16,4 +16,11 @@ RSpec.describe BFS::Bucket::FS do
16
16
  expect(bucket).to be_instance_of(described_class)
17
17
  expect(bucket.ls.to_a).to eq(['test.txt'])
18
18
  end
19
+
20
+ it 'should support custom perms' do
21
+ blob = BFS::Blob.new("file://#{tmpdir}/test.txt")
22
+ blob.create(perm: 0o666) {|w| w.write 'foo' }
23
+ expect(File.stat(File.join(tmpdir, 'test.txt')).mode).to eq(0o100666)
24
+ blob.close
25
+ end
19
26
  end
@@ -2,13 +2,19 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe BFS::TempWriter do
4
4
  let(:closer) { proc {} }
5
- subject { described_class.new 'test', nil, &closer }
5
+ subject { described_class.new 'test', &closer }
6
6
 
7
7
  it 'should behave like a File' do
8
8
  missing = ::File.public_instance_methods - subject.public_methods
9
9
  expect(missing).to be_empty
10
10
  end
11
11
 
12
+ it 'should support custom params' do
13
+ subject = described_class.new 'test', perm: 0o640, &closer
14
+ expect(subject.stat.mode).to eq(0o100640)
15
+ expect(subject.close).to be_truthy
16
+ end
17
+
12
18
  it 'should exectute a closer block' do
13
19
  expect(closer).to receive(:call).with(subject.path)
14
20
  expect(subject.close).to be_truthy
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-19 00:00:00.000000000 Z
11
+ date: 2020-02-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Minimalist abstraction for bucket storage
14
14
  email: dimitrij@blacksquaremedia.com
@@ -41,14 +41,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
- version: 2.4.0
44
+ version: 2.5.0
45
45
  required_rubygems_version: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  requirements: []
51
- rubygems_version: 3.0.6
51
+ rubygems_version: 3.1.2
52
52
  signing_key:
53
53
  specification_version: 4
54
54
  summary: Multi-platform cloud bucket adapter