bfs-gs 0.5.0 → 0.6.3
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.
- checksums.yaml +4 -4
 - data/bfs-gs.gemspec +1 -1
 - data/lib/bfs/bucket/gs.rb +27 -40
 - data/spec/bfs/bucket/gs_spec.rb +1 -1
 - metadata +6 -6
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 3d983acad48732ac1b9aefe1c9e24d38e69555a16d5888ab44628e3961af8248
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 5b2c07919f56f3063fa2dd2f6f7446305dca58fb0686e3c3a035812580a25735
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 22f44daf6914f672d9c214e0a2f048cdd413a977ba180ed08010cf5c6bef55f7bba85d792fc16f0389ea0027277ef83cc47573edf9d0482791d598438c36b7ad
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 213fa8a1545fbae970c01d54cb0665967a2b10db6c1f07603836d83a505125fe04870d3304a1688e6ec783eeee37a1f74e702333291a512a5ecfe096a90c1023
         
     | 
    
        data/bfs-gs.gemspec
    CHANGED
    
    | 
         @@ -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. 
     | 
| 
      
 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'
         
     | 
    
        data/lib/bfs/bucket/gs.rb
    CHANGED
    
    | 
         @@ -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  
     | 
| 
       24 
     | 
    
         
            -
                  def initialize(name, opts 
     | 
| 
       25 
     | 
    
         
            -
                    opts 
     | 
| 
       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 =  
     | 
| 
       33 
     | 
    
         
            -
                     
     | 
| 
       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 
     | 
| 
      
 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 
     | 
    
         
            -
                     
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
| 
      
 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:  
     | 
| 
      
 82 
     | 
    
         
            +
                    temp = Tempfile.new(File.basename(path), tempdir, encoding: encoding)
         
     | 
| 
       92 
83 
     | 
    
         
             
                    temp.close
         
     | 
| 
       93 
     | 
    
         
            -
                    file.download 
     | 
| 
      
 84 
     | 
    
         
            +
                    file.download(temp.path, **opts)
         
     | 
| 
       94 
85 
     | 
    
         | 
| 
       95 
     | 
    
         
            -
                    File.open(temp.path, encoding:  
     | 
| 
      
 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 
     | 
    
         
            -
               
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       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
         
     | 
    
        data/spec/bfs/bucket/gs_spec.rb
    CHANGED
    
    | 
         @@ -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]}/? 
     | 
| 
      
 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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.6.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:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-02-13 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. 
     | 
| 
      
 19 
     | 
    
         
            +
                    version: 0.6.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. 
     | 
| 
      
 26 
     | 
    
         
            +
                    version: 0.6.3
         
     | 
| 
       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. 
     | 
| 
      
 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. 
     | 
| 
      
 70 
     | 
    
         
            +
            rubygems_version: 3.1.2
         
     | 
| 
       71 
71 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       72 
72 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       73 
73 
     | 
    
         
             
            summary: GS bucket adapter for bfs
         
     |