bfs-gs 0.7.6 → 0.8.4

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: 204c52d94cef4322f9995de8bb647fab8db26bf4887168b43cfc9ca09d4bcc3a
4
- data.tar.gz: e1e1645d86d891053ee41ae8c177ee4c26fb37613c46195016dfe93ee8c19750
3
+ metadata.gz: 60feaa9cdb01df69a203ad3186b59ccff80d3ea90b08d2c3829c295daab69bbb
4
+ data.tar.gz: 1fa9e149a27ab27ba3e7f1f7da9b7b2aa68bd1e847d67ba3ebf00e963ff3dae5
5
5
  SHA512:
6
- metadata.gz: 0f7967ca40b047be697f909e853bdfa8db2dec44efbbb19c6f4e6ac8e711c5042b7fc43e5beb0a7f479da2dcfe32ffaadff7a7d1529af38d629e062e7314b33d
7
- data.tar.gz: e1b5ec3d09f475ab2f09bb31a3a3a6e7c6b83c33a2792ceb02c2ebcb00adb6eabe21bc021d12058a3b7e59c94158e01106aaabc8d675188d41a31b4c36eaa904
6
+ metadata.gz: f87a1efec3101b603f39adb8523655e947b7ebcd85369ea0bcbce462005c6ac12192a8a1a8e4127cc88e0502eb41b80232a63a51a1d29547ecf8ffe441c69e62
7
+ data.tar.gz: c13c82ee443f8857b88158152ae66fc98de11e7f7bbb27b11c5284957293c7a1216dd70c8e6098a4177fedac398ee1ef9af893e046dceffd7a6fb1d0f716eb50
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,26 +3,26 @@ 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
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
13
  described_class.new bucket_name, prefix: prefix
16
14
  end
17
15
 
18
- after :all do
19
- bucket = described_class.new bucket_name, prefix: 'x/'
16
+ let(:prefix) { "x/#{SecureRandom.uuid}/" }
17
+
18
+ after do
19
+ bucket = described_class.new bucket_name, prefix: prefix
20
20
  bucket.ls.each {|name| bucket.rm(name) }
21
21
  end
22
22
 
23
23
  it_behaves_like 'a bucket'
24
24
 
25
- it 'should resolve from URL' do
25
+ it 'resolves from URL' do
26
26
  bucket = BFS.resolve("gs://#{bucket_name}")
27
27
  expect(bucket).to be_instance_of(described_class)
28
28
  expect(bucket.name).to eq(bucket_name)
@@ -36,7 +36,7 @@ RSpec.describe BFS::Bucket::GS, gs: true do
36
36
  bucket.close
37
37
  end
38
38
 
39
- it 'should enumerate over a large number of files' do
39
+ it 'enumerates over a large number of files' do
40
40
  bucket = described_class.new bucket_name, prefix: 'm/'
41
41
  expect(bucket.ls('**/*').count).to eq(2121)
42
42
  bucket.close
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.6
4
+ version: 0.8.4
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-10 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.6
19
+ version: 0.8.4
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.6
26
+ version: 0.8.4
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