bfs-gs 0.7.5 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '068f4b652ec2ef87b680e2ababa9de943b87807626a662fc645813d8fe038eca'
4
- data.tar.gz: de6b4d78c33dee9c85929031cf29f5b3fc19c9a0d0d28ae8735609f5f5f00b1e
3
+ metadata.gz: 361c56113182e489c7373029e15e134fe2f65a0cdec35b00f97a72ed8b8b94b7
4
+ data.tar.gz: 8f969343d8848f1ba073ce0948836290591fd1096995ed0456a7715c89e7cc70
5
5
  SHA512:
6
- metadata.gz: 7d15bb556314fa4e06c24742890a47427b4b7af5e946120c7e24079e613dd236384146af23e67349e5625e7bcd283a5900394a1fb75144cff885bb7020231b76
7
- data.tar.gz: 22bd175fecc3c3e75d3a60154a760c1c87c5e773f5ec6e1dd90af001b4ef91a799595d9942c3a5128542a0cd58a16a0f4a48e52e6a6b850657cacb66bc089bcd
6
+ metadata.gz: '04359b81560d94527826da03a81d00b2f399a7e2d77e8d5c563aa6f1587d8163aa863f69288aaecdc5213b07e1d26e579c129958d7d761a797ddf11bc013de84'
7
+ data.tar.gz: b3656acbcfaf1074bdcebabb4c6df76801bb913bceb37bb5be5a68e4099543d0a31e0953f7606af280faa2368aa415e4d36bce375e0ab6b87241d39b05158165
data/lib/bfs/bucket/gs.rb CHANGED
@@ -33,14 +33,18 @@ module BFS
33
33
 
34
34
  # Lists the contents of a bucket using a glob pattern
35
35
  def ls(pattern = '**/*', **opts)
36
- prefix = pattern[%r{^[^*?\{\}\[\]]+/}]
37
- prefix = File.join(*[@prefix, prefix].compact) if @prefix
38
- opts = opts.merge(prefix: prefix) if prefix
36
+ Enumerator.new do |acc|
37
+ walk(pattern, **opts) do |name, _|
38
+ acc << name
39
+ end
40
+ end
41
+ end
39
42
 
40
- Enumerator.new do |y|
41
- @bucket.files(**opts).all do |file|
42
- name = trim_prefix(file.name)
43
- y << name if File.fnmatch?(pattern, name, File::FNM_PATHNAME)
43
+ # Iterates over the contents of a bucket using a glob pattern
44
+ def glob(pattern = '**/*', **opts)
45
+ Enumerator.new do |acc|
46
+ walk(pattern, **opts) do |name, file|
47
+ acc << file_info(name, file)
44
48
  end
45
49
  end
46
50
  end
@@ -52,14 +56,14 @@ module BFS
52
56
  raise BFS::FileNotFound, trim_prefix(path) unless file
53
57
 
54
58
  name = trim_prefix(file.name)
55
- BFS::FileInfo.new(path: name, size: file.size, mtime: file.updated_at.to_time, content_type: file.content_type, metadata: norm_meta(file.metadata))
59
+ file_info(name, file)
56
60
  end
57
61
 
58
62
  # Creates a new file and opens it for writing
59
63
  def create(path, encoding: self.encoding, perm: self.perm, **opts, &block)
60
64
  opts[:metadata] = norm_meta(opts[:metadata])
61
65
  path = full_path(path)
62
- BFS::TempWriter.new(path, encoding: encoding, perm: perm) do |t|
66
+ BFS::Writer.new(path, encoding: encoding, perm: perm) do |t|
63
67
  File.open(t, encoding: encoding) do |file|
64
68
  @bucket.create_file(file, path, **opts)
65
69
  end
@@ -94,6 +98,23 @@ module BFS
94
98
 
95
99
  file.copy(full_path(dst), **opts)
96
100
  end
101
+
102
+ private
103
+
104
+ def walk(pattern, **opts)
105
+ prefix = pattern[%r{^[^*?\{\}\[\]]+/}]
106
+ prefix = File.join(*[@prefix, prefix].compact) if @prefix
107
+ opts = opts.merge(prefix: prefix) if prefix
108
+
109
+ @bucket.files(**opts).all do |file|
110
+ name = trim_prefix(file.name)
111
+ yield(name, file) if File.fnmatch?(pattern, name, File::FNM_PATHNAME)
112
+ end
113
+ end
114
+
115
+ def file_info(name, file)
116
+ BFS::FileInfo.new(path: name, size: file.size, mtime: file.updated_at.to_time, content_type: file.content_type, metadata: norm_meta(file.metadata))
117
+ end
97
118
  end
98
119
  end
99
120
  end
@@ -3,40 +3,41 @@ require 'spec_helper'
3
3
  # silence warnings
4
4
  module Google::Auth::CredentialsLoader
5
5
  def warn_if_cloud_sdk_credentials(*); end
6
- module_function :warn_if_cloud_sdk_credentials # rubocop:disable Style/AccessModifierDeclarations
6
+ module_function :warn_if_cloud_sdk_credentials
7
7
  end
8
8
 
9
- sandbox = { project: 'bogus', bucket: 'bsm-bfs-unittest' }.freeze
9
+ bucket_name = 'bsm-bfs-unittest'
10
10
 
11
11
  RSpec.describe BFS::Bucket::GS, gs: true do
12
- let(:prefix) { "x/#{SecureRandom.uuid}/" }
13
-
14
12
  subject do
15
- described_class.new sandbox[:bucket], project_id: sandbox[:project], prefix: prefix
13
+ described_class.new bucket_name, prefix: prefix
16
14
  end
17
- after :all do
18
- bucket = described_class.new sandbox[:bucket], project_id: sandbox[:project], prefix: 'x/'
15
+
16
+ let(:prefix) { "x/#{SecureRandom.uuid}/" }
17
+
18
+ after do
19
+ bucket = described_class.new bucket_name, prefix: prefix
19
20
  bucket.ls.each {|name| bucket.rm(name) }
20
21
  end
21
22
 
22
23
  it_behaves_like 'a bucket'
23
24
 
24
- it 'should resolve from URL' do
25
- bucket = BFS.resolve("gs://#{sandbox[:bucket]}/?project_id=#{sandbox[:project]}")
25
+ it 'resolves from URL' do
26
+ bucket = BFS.resolve("gs://#{bucket_name}")
26
27
  expect(bucket).to be_instance_of(described_class)
27
- expect(bucket.name).to eq(sandbox[:bucket])
28
+ expect(bucket.name).to eq(bucket_name)
28
29
  expect(bucket.instance_variable_get(:@prefix)).to be_nil
29
30
  bucket.close
30
31
 
31
- bucket = BFS.resolve("gs://#{sandbox[:bucket]}/a/b/")
32
+ bucket = BFS.resolve("gs://#{bucket_name}/a/b/")
32
33
  expect(bucket).to be_instance_of(described_class)
33
- expect(bucket.name).to eq(sandbox[:bucket])
34
+ expect(bucket.name).to eq(bucket_name)
34
35
  expect(bucket.instance_variable_get(:@prefix)).to eq('a/b')
35
36
  bucket.close
36
37
  end
37
38
 
38
- it 'should enumerate over a large number of files' do
39
- bucket = described_class.new sandbox[:bucket], project_id: sandbox[:project], prefix: 'm/'
39
+ it 'enumerates over a large number of files' do
40
+ bucket = described_class.new bucket_name, prefix: 'm/'
40
41
  expect(bucket.ls('**/*').count).to eq(2121)
41
42
  bucket.close
42
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bfs-gs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.8.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: 2020-11-02 00:00:00.000000000 Z
11
+ date: 2021-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bfs
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.7.5
19
+ version: 0.8.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.7.5
26
+ version: 0.8.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: google-cloud-storage
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubygems_version: 3.1.2
70
+ rubygems_version: 3.2.15
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: GS bucket adapter for bfs