bfs 0.7.6 → 0.8.0
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 +4 -4
- data/lib/bfs/blob.rb +3 -0
- data/lib/bfs/bucket/fs.rb +1 -1
- data/lib/bfs/bucket/in_mem.rb +7 -22
- data/lib/bfs/helpers.rb +30 -18
- data/spec/bfs/helpers_spec.rb +17 -17
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3de22f9cab6ba21d594854a2fcec49cc215b7c10c6f6b5b9cb1528ba6ce96b59
|
4
|
+
data.tar.gz: cc3b427ff41229556b7b39a9d0ad5d61afdd0439fa984aafadd0aa9635ac4664
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 569ac3d4e157eebf08f948eab831f214a900d29a96028a703d541d3fa7de7fdcde6a2cb11413ff802c459ff163cff15feb00c3477abcae7b18d77c302255d529
|
7
|
+
data.tar.gz: 2804530bcc9aaf60f1b475a6948b357242dc96e15788835e34d6cc1989ec7bda8e0bd66372427ce4aa9d5b923eda5468a9c33087b716ac3ca379f391a6192f43
|
data/lib/bfs/blob.rb
CHANGED
@@ -32,6 +32,9 @@ module BFS
|
|
32
32
|
end
|
33
33
|
|
34
34
|
# Creates the blob and opens it for writing.
|
35
|
+
# If a block is passed the writer is automatically committed in the end.
|
36
|
+
# If no block is passed, you must manually call #commit to persist the
|
37
|
+
# result.
|
35
38
|
def create(**opts, &block)
|
36
39
|
@bucket.create(path, **opts, &block)
|
37
40
|
end
|
data/lib/bfs/bucket/fs.rb
CHANGED
@@ -42,7 +42,7 @@ module BFS
|
|
42
42
|
full = @root.join(norm_path(path))
|
43
43
|
FileUtils.mkdir_p(full.dirname.to_s)
|
44
44
|
|
45
|
-
BFS::
|
45
|
+
BFS::Writer.new(full, encoding: encoding, perm: perm) do |temp|
|
46
46
|
FileUtils.mv temp, full.to_s
|
47
47
|
end.perform(&block)
|
48
48
|
end
|
data/lib/bfs/bucket/in_mem.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'bfs'
|
2
2
|
require 'stringio'
|
3
|
+
require 'delegate'
|
3
4
|
|
4
5
|
module BFS
|
5
6
|
module Bucket
|
@@ -8,34 +9,18 @@ module BFS
|
|
8
9
|
Entry = Struct.new(:io, :mtime, :content_type, :metadata)
|
9
10
|
|
10
11
|
class Writer < DelegateClass(::StringIO)
|
11
|
-
|
12
|
-
|
12
|
+
include BFS::Writer::Mixin
|
13
|
+
|
14
|
+
def initialize(encoding:, &on_commit)
|
15
|
+
@on_commit = on_commit
|
13
16
|
|
14
17
|
sio = StringIO.new
|
15
18
|
sio.set_encoding(encoding)
|
16
19
|
super sio
|
17
20
|
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
@closer&.call(self)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def close!
|
26
|
-
__getobj__.close
|
27
|
-
end
|
28
|
-
|
29
|
-
def perform
|
30
|
-
return self unless block_given?
|
31
|
-
|
32
|
-
begin
|
33
|
-
yield self
|
34
|
-
close
|
35
|
-
ensure
|
36
|
-
close!
|
37
|
-
end
|
38
|
-
end
|
22
|
+
alias close! close
|
23
|
+
alias commit_ref __getobj__
|
39
24
|
end
|
40
25
|
|
41
26
|
def initialize(**opts)
|
data/lib/bfs/helpers.rb
CHANGED
@@ -2,33 +2,45 @@ require 'tempfile'
|
|
2
2
|
require 'delegate'
|
3
3
|
|
4
4
|
module BFS
|
5
|
-
class
|
6
|
-
|
7
|
-
|
5
|
+
class Writer < DelegateClass(::Tempfile)
|
6
|
+
module Mixin
|
7
|
+
def perform
|
8
|
+
return self unless block_given?
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
begin
|
11
|
+
yield self
|
12
|
+
commit
|
13
|
+
ensure
|
14
|
+
discard
|
15
|
+
end
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
yield self
|
18
|
+
def commit
|
19
19
|
close
|
20
|
+
return false if @on_commit.nil?
|
21
|
+
|
22
|
+
@on_commit.call(commit_ref)
|
23
|
+
true
|
20
24
|
ensure
|
25
|
+
discard
|
26
|
+
end
|
27
|
+
|
28
|
+
def discard
|
29
|
+
@on_commit = nil
|
21
30
|
close!
|
22
31
|
end
|
23
32
|
end
|
24
33
|
|
25
|
-
|
26
|
-
return if closed?
|
34
|
+
include Mixin
|
27
35
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
36
|
+
def initialize(name, tempdir: nil, perm: nil, **opts, &on_commit)
|
37
|
+
@on_commit = on_commit
|
38
|
+
|
39
|
+
tempfile = ::Tempfile.new(File.basename(name.to_s), tempdir, **opts)
|
40
|
+
tempfile.chmod(perm) if perm
|
41
|
+
super tempfile
|
32
42
|
end
|
43
|
+
|
44
|
+
alias commit_ref path
|
33
45
|
end
|
34
46
|
end
|
data/spec/bfs/helpers_spec.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe BFS::
|
4
|
-
let(:
|
5
|
-
subject { described_class.new 'test', &
|
6
|
-
|
7
|
-
it 'should behave like a File' do
|
8
|
-
missing = ::File.public_instance_methods - subject.public_methods
|
9
|
-
expect(missing).to be_empty
|
10
|
-
end
|
3
|
+
RSpec.describe BFS::Writer, core: true do
|
4
|
+
let(:on_commit) { proc { true } }
|
5
|
+
subject { described_class.new 'test', &on_commit }
|
11
6
|
|
12
7
|
it 'should support custom params' do
|
13
|
-
subject = described_class.new 'test', perm: 0o640, &
|
8
|
+
subject = described_class.new 'test', perm: 0o640, &on_commit
|
14
9
|
expect(subject.stat.mode).to eq(0o100640)
|
15
|
-
expect(subject.
|
10
|
+
expect(subject.commit).to be(true)
|
16
11
|
end
|
17
12
|
|
18
|
-
it 'should execute a
|
19
|
-
expect(
|
20
|
-
expect(subject.
|
21
|
-
expect(subject.
|
13
|
+
it 'should execute a on_commit block' do
|
14
|
+
expect(on_commit).to receive(:call).with(subject.path).once
|
15
|
+
expect(subject.commit).to be(true)
|
16
|
+
expect(subject.commit).to be(false)
|
22
17
|
end
|
23
18
|
|
24
|
-
it 'may skip
|
25
|
-
expect(
|
26
|
-
expect(subject.
|
19
|
+
it 'may skip on_commit block' do
|
20
|
+
expect(on_commit).not_to receive(:call)
|
21
|
+
expect(subject.discard).to be(true)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should not auto-commit on close' do
|
25
|
+
expect(on_commit).not_to receive(:call)
|
26
|
+
expect(subject.close).to be_nil
|
27
27
|
end
|
28
28
|
end
|
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.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitrij Denissenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Minimalist abstraction for bucket storage
|
14
14
|
email: dimitrij@blacksquaremedia.com
|
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '0'
|
53
53
|
requirements: []
|
54
|
-
rubygems_version: 3.1.
|
54
|
+
rubygems_version: 3.1.4
|
55
55
|
signing_key:
|
56
56
|
specification_version: 4
|
57
57
|
summary: Multi-platform cloud bucket adapter
|