bfs 0.3.2 → 0.3.3

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: c365a73c082d9bd75ec6ea3495f03bf73d1b810e4d6cf56c2f9138912c96ac21
4
- data.tar.gz: ebba20256a185f0bf93985eeb021db628620c5f66e777d212655977728aab831
3
+ metadata.gz: 7ed077904a46a574dd780eaa9ce2ca804ebe4a11eac9b744dff1389bd9a34169
4
+ data.tar.gz: 1ae5d64274163768624e28b6d7cd5cba63b2237dffbd88dc8c481a0515c7b353
5
5
  SHA512:
6
- metadata.gz: bda0bb7e8b2e16ae17cdac98ed6f653fdd699a186d1c555827018d9f3881a77e54725b5a8a5a666c9c5367745cfe0163b96d8bb21323bc6e0534f8e40d6b7fa1
7
- data.tar.gz: 9ac50f7252934f147a9f074ca4d53689bb881c9a8b8c4970a3cb9e3a559859b4f1152dcdacd7a4d3d27f29b8b3f32efdca502d53f2fbde4b85262bcc265de4ca
6
+ metadata.gz: 1d60da76feb312e7bef9c0d796e33e9161830ce59ef9a5f60bb2d3e5a697b7d3a55b6820ebc5defe8601b5c34db2ee19850f6998195ea8088f9e3fb1dafa69a6
7
+ data.tar.gz: 151543a8a0f1b48ce925c261a580b06960db41ceab7f3fd83cac8ad9479fa7ffa0d29338eb6b2518cf9110bba52afaf80830451b843e3ad2f337d53271fe75f7
data/lib/bfs.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'uri'
2
2
 
3
3
  module BFS
4
- FileInfo = Struct.new(:path, :size, :mtime)
4
+ FileInfo = Struct.new(:path, :size, :mtime, :content_type, :metadata)
5
5
 
6
6
  def self.register(scheme, &resolver)
7
7
  @registry ||= {}
@@ -24,7 +24,7 @@ module BFS
24
24
  def info(path, _opts={})
25
25
  full = @root.join(norm_path(path))
26
26
  path = trim_prefix(full.to_s)
27
- BFS::FileInfo.new(path, full.size, full.mtime)
27
+ BFS::FileInfo.new(path, full.size, full.mtime, nil, {})
28
28
  rescue Errno::ENOENT
29
29
  raise BFS::FileNotFound, path
30
30
  end
@@ -5,12 +5,17 @@ module BFS
5
5
  module Bucket
6
6
  # InMem buckets are useful for tests
7
7
  class InMem < Abstract
8
- Entry = Struct.new(:io, :mtime)
8
+ Entry = Struct.new(:io, :mtime, :content_type, :metadata)
9
9
 
10
10
  def initialize
11
11
  @files = {}
12
12
  end
13
13
 
14
+ # Reset bucket and clear all files.
15
+ def clear
16
+ @files.clear
17
+ end
18
+
14
19
  # Lists the contents of a bucket using a glob pattern
15
20
  def ls(pattern='**/*', _opts={})
16
21
  Enumerator.new do |y|
@@ -26,13 +31,13 @@ module BFS
26
31
  raise BFS::FileNotFound, path unless @files.key?(path)
27
32
 
28
33
  entry = @files[path]
29
- BFS::FileInfo.new(path, entry.io.size, entry.mtime)
34
+ BFS::FileInfo.new(path, entry.io.size, entry.mtime, entry.content_type, entry.metadata)
30
35
  end
31
36
 
32
37
  # Creates a new file and opens it for writing
33
- def create(path, _opts={}, &block)
38
+ def create(path, opts={}, &block)
34
39
  io = StringIO.new
35
- @files[norm_path(path)] = Entry.new(io, Time.now)
40
+ @files[norm_path(path)] = Entry.new(io, Time.now, opts[:content_type], opts[:metadata] || {})
36
41
  return io unless block
37
42
 
38
43
  begin
@@ -17,10 +17,10 @@ RSpec.describe BFS::Blob do
17
17
 
18
18
  it 'should write/read' do
19
19
  expect { subject.read }.to raise_error(BFS::FileNotFound)
20
- subject.write('TESTDATA')
20
+ subject.write('TESTDATA', content_type: 'text/plain', metadata: { 'key' => 'val' })
21
21
 
22
22
  info = subject.info
23
- expect(info).to eq(BFS::FileInfo.new('path/to/file.txt', 8, info.mtime))
23
+ expect(info).to eq(BFS::FileInfo.new('path/to/file.txt', 8, info.mtime, 'text/plain', 'key' => 'val'))
24
24
  expect(info.mtime).to be_within(1).of(Time.now)
25
25
 
26
26
  expect(subject.read).to eq('TESTDATA')
@@ -49,11 +49,11 @@ RSpec.describe BFS::Blob do
49
49
  it 'should write/read' do
50
50
  expect { subject.read }.to raise_error(BFS::FileNotFound)
51
51
 
52
- subject.write('TESTDATA')
52
+ subject.write('TESTDATA', content_type: 'text/plain', metadata: { 'key' => 'val' })
53
53
  expect(subject.read).to eq('TESTDATA')
54
54
 
55
55
  info = subject.info
56
- expect(info).to eq(BFS::FileInfo.new(path, 8, info.mtime))
56
+ expect(info).to eq(BFS::FileInfo.new(path, 8, info.mtime, nil, {}))
57
57
  expect(info.mtime).to be_within(1).of(Time.now)
58
58
 
59
59
  expect(Pathname.glob("#{tmpdir}/**/*").select(&:file?).map(&:to_s)).to eq [
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.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-12 00:00:00.000000000 Z
11
+ date: 2018-11-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Minimalist abstraction for bucket storage
14
14
  email: dimitrij@blacksquaremedia.com