bfs-gs 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bfs/bucket/gs.rb +29 -8
  3. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 122c702df719f9cad5d305bfeec70c467ce65bda54eafdac2a73c098dbcdee96
4
- data.tar.gz: 123e412eea2104d88de883be1dba69ab628a91e8b315b5189ebd5cea6e4faad8
3
+ metadata.gz: 361c56113182e489c7373029e15e134fe2f65a0cdec35b00f97a72ed8b8b94b7
4
+ data.tar.gz: 8f969343d8848f1ba073ce0948836290591fd1096995ed0456a7715c89e7cc70
5
5
  SHA512:
6
- metadata.gz: eea22b92b0ad8ccbdceab4ef01cd7462877deee8fcc395faca70c8b338bf4edaaa1d592f31642b189383e78649132e6c9810c16efea707a962a0f51052cdb77b
7
- data.tar.gz: ed44218f277442eca35210dc574409167857c2ff50f9f6a9b1af3680c9430dd39089750a057370d0a2573c674152cacf440cb3d2f620d69f4b8eeb5644f353c2
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,7 +56,7 @@ 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
@@ -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
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.8.2
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: 2021-05-04 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.8.2
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.8.2
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.4
70
+ rubygems_version: 3.2.15
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: GS bucket adapter for bfs