bfs-gs 0.6.1 → 0.7.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bfs-gs.gemspec +1 -1
  3. data/lib/bfs/bucket/gs.rb +16 -29
  4. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a2d8c79d6fb88844a374b8f776967c20fcd7477815e4868fb2cb0534886a142
4
- data.tar.gz: 65c9d7dbeecc7be84d77423a6fdfc40848511809af145315b6bf21de3807a9d6
3
+ metadata.gz: a2d89afa0f45efa9b6fd19cc525754cc52dd0860df44c1ca042371df28c1f75a
4
+ data.tar.gz: b5ec4ef496facbc6f062c81017ed0ed35f0a06f7e512b5a657688130bed041a7
5
5
  SHA512:
6
- metadata.gz: 57b26012045b16b2dade58bd711c44dfd75cfede1bcba4a534386aab11ef2e44a9d3951e6f7f553594e7d0f3d0e44c05ee55d6243d632c1afe5f18e6eb2ac27e
7
- data.tar.gz: 2e2eec782845273aebe39753d4424943b42519e70d39973ebd50969a5ddb4d320eca49fc70e241f37891deac5eb90ff8be50de19de7a3b654c1ff1758c61c922
6
+ metadata.gz: 1c7c2c221cb15b740721a1224a73ffb1203fefd0431253f8b07e12cec454aa8d1b8806381bbe5036ee607fdc582f43ab98a862471ac3c37e76dcb7cad79ab9c1
7
+ data.tar.gz: a8f78a4813033d7ebe7cb244ae68a3424aadbf251d845f909614325e35931bf85816a4e3aceffdf51e8520e9023aa0fbb1528a46a18801f9335b71ae16864de0
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- spec/*`.split("\n")
17
17
  s.require_paths = ['lib']
18
- s.required_ruby_version = '>= 2.5.0'
18
+ s.required_ruby_version = '>= 2.6.0'
19
19
 
20
20
  s.add_dependency 'bfs', s.version
21
21
  s.add_dependency 'google-cloud-storage', '~> 1.18'
@@ -1,6 +1,5 @@
1
1
  require 'bfs'
2
2
  require 'google/cloud/storage'
3
- require 'cgi'
4
3
 
5
4
  module BFS
6
5
  module Bucket
@@ -21,17 +20,11 @@ module BFS
21
20
  # @option opts [String] :acl set the default ACL.
22
21
  # @option opts [Google::Cloud::Storage] :client custom client.
23
22
  # @option opts [String] :encoding Custom encoding.
24
- def initialize(name, **opts)
25
- opts = opts.dup
26
- opts.keys.each do |key|
27
- val = opts.delete(key)
28
- opts[key.to_sym] = val unless val.nil?
29
- end
23
+ def initialize(name, prefix: nil, acl: nil, client: nil, **opts)
30
24
  super(**opts)
31
25
 
32
- @prefix = opts.delete(:prefix)
33
- acl = opts.delete(:acl)
34
- client = opts.delete(:client) || Google::Cloud::Storage.new(**opts)
26
+ @prefix = prefix
27
+ client ||= Google::Cloud::Storage.new(**opts)
35
28
 
36
29
  @name = name.to_s
37
30
  @bucket = client.bucket(@name)
@@ -59,16 +52,15 @@ module BFS
59
52
  raise BFS::FileNotFound, trim_prefix(path) unless file
60
53
 
61
54
  name = trim_prefix(file.name)
62
- BFS::FileInfo.new(name, file.size, file.updated_at.to_time, file.content_type, norm_meta(file.metadata))
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))
63
56
  end
64
57
 
65
58
  # Creates a new file and opens it for writing
66
- def create(path, **opts, &block)
59
+ def create(path, encoding: self.encoding, perm: self.perm, **opts, &block)
67
60
  opts[:metadata] = norm_meta(opts[:metadata])
68
61
  path = full_path(path)
69
- enc = opts.delete(:encoding) || @encoding
70
- temp = BFS::TempWriter.new(path, encoding: enc) do |t|
71
- File.open(t, encoding: enc) do |file|
62
+ temp = BFS::TempWriter.new(path, encoding: encoding, perm: perm) do |t|
63
+ File.open(t, encoding: encoding) do |file|
72
64
  @bucket.create_file(file, path, **opts)
73
65
  end
74
66
  end
@@ -82,17 +74,16 @@ module BFS
82
74
  end
83
75
 
84
76
  # Opens an existing file for reading
85
- def open(path, **opts, &block)
77
+ def open(path, encoding: self.encoding, tempdir: nil, **opts, &block)
86
78
  path = full_path(path)
87
- enc = opts.delete(:encoding) || @encoding
88
79
  file = @bucket.file(path)
89
80
  raise BFS::FileNotFound, trim_prefix(path) unless file
90
81
 
91
- temp = Tempfile.new(File.basename(path), encoding: enc)
82
+ temp = Tempfile.new(File.basename(path), tempdir, encoding: encoding)
92
83
  temp.close
93
- file.download temp.path, opts
84
+ file.download(temp.path, **opts)
94
85
 
95
- File.open(temp.path, encoding: enc, &block)
86
+ File.open(temp.path, encoding: encoding, &block)
96
87
  end
97
88
 
98
89
  # Deletes a file.
@@ -114,16 +105,12 @@ module BFS
114
105
  end
115
106
  end
116
107
 
117
- BFS.register('gs') do |url|
118
- params = CGI.parse(url.query.to_s)
119
- prefix = BFS.norm_path(params.key?('prefix') ? params['prefix'].first : url.path)
108
+ BFS.register('gs') do |url, opts|
109
+ prefix = BFS.norm_path(opts.key?(:prefix) ? opts[:prefix] : url.path)
120
110
  prefix = nil if prefix.empty?
121
111
 
122
- BFS::Bucket::GS.new url.host,
112
+ BFS::Bucket::GS.new url.host, **opts.slice(:project_id, :credentials, :acl),
123
113
  prefix: prefix,
124
- project_id: params.key?('project_id') ? params['project_id'].first : nil,
125
- credentials: params.key?('credentials') ? params['credentials'].first : nil,
126
- acl: params.key?('acl') ? params['acl'].first : nil,
127
- timeout: params.key?('timeout') ? params['timeout'].first.to_i : nil,
128
- retries: params.key?('retries') ? params['retries'].first.to_i : nil
114
+ timeout: opts.key?(:timeout) ? opts[:timeout].to_i : nil,
115
+ retries: opts.key?(:retries) ? opts[:retries].to_i : nil
129
116
  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.6.1
4
+ version: 0.7.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-02-11 00:00:00.000000000 Z
11
+ date: 2020-05-28 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.6.1
19
+ version: 0.7.0
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.6.1
26
+ version: 0.7.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: google-cloud-storage
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -60,7 +60,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: 2.5.0
63
+ version: 2.6.0
64
64
  required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="