bfs-gs 0.5.1 → 0.6.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: 51743478164e7dfd25c540ea4c29c26125ff748c280dcb78c1966c5e0271728b
4
- data.tar.gz: 871089ee32de429d791d356198798ce1d938ef4879ca9e23eacbb21a626bc517
3
+ metadata.gz: ae53e3d99f879a7365cb5dd3ca06b5407cdd4542cef07a839a2b1362f83c8deb
4
+ data.tar.gz: 637c8a48a18b2df89381ca6ff16fbd2d4d0f993e025517d83de3032083b167ae
5
5
  SHA512:
6
- metadata.gz: aa0bc35d3ed5d50c4c547cbf811b8609e73efc636662f338a273dbf13a9f825d1711c542640526483fce691c0a18cd87af42e2e88e2825df8a16064f18f9ba3d
7
- data.tar.gz: b6c5588806e7ed63b3a5ed332a1583107a0127307981ee260f6ad8ef30c3dc1d5f8682159deecbbafa5fe71523d8089e3c25be73d5e86d6309d02d3bfa6226fc
6
+ metadata.gz: 59dbc0f2e5cd99bc71af65e922eaa439e41392763c80e13ce71a50fb40aaa27ffda796dc46615e76340cf799d584ec1bb61438e3d8b47db75f556e51d7c3639e
7
+ data.tar.gz: '08c336ee7b0a81be35f230b23b603a08f2523ae4cd5d1c04aee50b0af0576dbaf86bb053ad796cd9687a350e15d9642e38654a055361f370561f938286e7e430'
@@ -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.4.0'
18
+ s.required_ruby_version = '>= 2.5.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
@@ -20,18 +19,12 @@ module BFS
20
19
  # @option opts [Integer] :timeout request timeout, in seconds.
21
20
  # @option opts [String] :acl set the default ACL.
22
21
  # @option opts [Google::Cloud::Storage] :client custom client.
23
- # @option opts [String] :encoding default encoding to use, default: 'binary'
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
30
- super(opts)
22
+ # @option opts [String] :encoding Custom encoding.
23
+ def initialize(name, prefix: nil, acl: nil, client: nil, **opts)
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)
@@ -39,13 +32,13 @@ module BFS
39
32
  end
40
33
 
41
34
  # Lists the contents of a bucket using a glob pattern
42
- def ls(pattern='**/*', opts={})
35
+ def ls(pattern = '**/*', **opts)
43
36
  prefix = pattern[%r{^[^\*\?\{\}\[\]]+/}]
44
37
  prefix = File.join(*[@prefix, prefix].compact) if @prefix
45
38
  opts = opts.merge(prefix: prefix) if prefix
46
39
 
47
40
  Enumerator.new do |y|
48
- @bucket.files(opts).all do |file|
41
+ @bucket.files(**opts).all do |file|
49
42
  name = trim_prefix(file.name)
50
43
  y << name if File.fnmatch?(pattern, name, File::FNM_PATHNAME)
51
44
  end
@@ -53,23 +46,22 @@ module BFS
53
46
  end
54
47
 
55
48
  # Info returns the object info
56
- def info(path, _opts={})
49
+ def info(path, **_opts)
57
50
  path = full_path(path)
58
51
  file = @bucket.file(path)
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|
72
- @bucket.create_file(file, path, opts)
62
+ temp = BFS::TempWriter.new(path, encoding: encoding, perm: perm) do |t|
63
+ File.open(t, encoding: encoding) do |file|
64
+ @bucket.create_file(file, path, **opts)
73
65
  end
74
66
  end
75
67
  return temp unless block
@@ -82,48 +74,43 @@ 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.
99
- def rm(path, opts={})
90
+ def rm(path, **opts)
100
91
  path = full_path(path)
101
92
  file = @bucket.file(path)
102
- file&.delete(opts)
93
+ file&.delete(**opts)
103
94
  end
104
95
 
105
96
  # Copies a file.
106
- def cp(src, dst, opts={})
97
+ def cp(src, dst, **opts)
107
98
  src = full_path(src)
108
99
  file = @bucket.file(src)
109
100
  raise BFS::FileNotFound, trim_prefix(src) unless file
110
101
 
111
- file.copy(full_path(dst), opts)
102
+ file.copy(full_path(dst), **opts)
112
103
  end
113
104
  end
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,
123
- 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
112
+ BFS::Bucket::GS.new url.host, **opts.slice(:project_id, :credentials, :acl),
113
+ prefix: prefix,
114
+ timeout: opts.key?(:timeout) ? opts[:timeout].to_i : nil,
115
+ retries: opts.key?(:retries) ? opts[:retries].to_i : nil
129
116
  end
@@ -30,7 +30,7 @@ RSpec.describe BFS::Bucket::GS, if: run_spec do
30
30
  it_behaves_like 'a bucket'
31
31
 
32
32
  it 'should resolve from URL' do
33
- bucket = BFS.resolve("gs://#{sandbox[:bucket]}/?acl=private&project_id=#{sandbox[:project]}")
33
+ bucket = BFS.resolve("gs://#{sandbox[:bucket]}/?project_id=#{sandbox[:project]}")
34
34
  expect(bucket).to be_instance_of(described_class)
35
35
  expect(bucket.name).to eq(sandbox[:bucket])
36
36
  expect(bucket.instance_variable_get(:@prefix)).to be_nil
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.5.1
4
+ version: 0.6.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: 2019-10-09 00:00:00.000000000 Z
11
+ date: 2020-02-17 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.5.1
19
+ version: 0.6.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.5.1
26
+ version: 0.6.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: google-cloud-storage
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -60,14 +60,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: 2.4.0
63
+ version: 2.5.0
64
64
  required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubygems_version: 3.0.3
70
+ rubygems_version: 3.1.2
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: GS bucket adapter for bfs