bfs 0.7.4 → 0.7.5
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/lib/bfs/bucket/fs.rb +3 -8
- data/lib/bfs/bucket/in_mem.rb +33 -12
- data/lib/bfs/helpers.rb +22 -8
- data/spec/bfs/helpers_spec.rb +5 -0
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 61e0b8f8c56a60a7d3b933aacce3e476d400389bfa991b14b3adddf3af667108
         | 
| 4 | 
            +
              data.tar.gz: ab0da145b04da234825c0c418a5e5dc0fc3028627431072df04c5f2f7f45b652
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 4ba809e64dfdab6a918a807323acffd3228783d5c4c6a3ecc9712011ca742a2510e830fe7c2cbf73f2b0d900bdd9d5a9386e133c16ba3170b6be972366db0405
         | 
| 7 | 
            +
              data.tar.gz: 1999418b45ed5c090b7bf578f9ea6c8964eb49538b98068c6eff583480b1682d63ef61a04a3f9183ba54f027e9bd876b618d5297795c469c43127474e808449d
         | 
    
        data/lib/bfs/bucket/fs.rb
    CHANGED
    
    | @@ -42,14 +42,9 @@ module BFS | |
| 42 42 | 
             
                    full = @root.join(norm_path(path))
         | 
| 43 43 | 
             
                    FileUtils.mkdir_p(full.dirname.to_s)
         | 
| 44 44 |  | 
| 45 | 
            -
                     | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
                    begin
         | 
| 49 | 
            -
                      yield temp
         | 
| 50 | 
            -
                    ensure
         | 
| 51 | 
            -
                      temp.close
         | 
| 52 | 
            -
                    end
         | 
| 45 | 
            +
                    BFS::TempWriter.new(full, encoding: encoding, perm: perm) do |temp|
         | 
| 46 | 
            +
                      FileUtils.mv temp, full.to_s
         | 
| 47 | 
            +
                    end.perform(&block)
         | 
| 53 48 | 
             
                  end
         | 
| 54 49 |  | 
| 55 50 | 
             
                  # Opens an existing file for reading
         | 
    
        data/lib/bfs/bucket/in_mem.rb
    CHANGED
    
    | @@ -7,6 +7,36 @@ module BFS | |
| 7 7 | 
             
                class InMem < Abstract
         | 
| 8 8 | 
             
                  Entry = Struct.new(:io, :mtime, :content_type, :metadata)
         | 
| 9 9 |  | 
| 10 | 
            +
                  class Writer < DelegateClass(::StringIO)
         | 
| 11 | 
            +
                    def initialize(encoding:, &closer)
         | 
| 12 | 
            +
                      @closer = closer
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                      sio = StringIO.new
         | 
| 15 | 
            +
                      sio.set_encoding(encoding)
         | 
| 16 | 
            +
                      super sio
         | 
| 17 | 
            +
                    end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    def close
         | 
| 20 | 
            +
                      close!
         | 
| 21 | 
            +
                      @closer&.call(self)
         | 
| 22 | 
            +
                    end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                    def close!
         | 
| 25 | 
            +
                      __getobj__.close
         | 
| 26 | 
            +
                    end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                    def perform(&block)
         | 
| 29 | 
            +
                      return self unless block
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                      begin
         | 
| 32 | 
            +
                        yield self
         | 
| 33 | 
            +
                        close
         | 
| 34 | 
            +
                      ensure
         | 
| 35 | 
            +
                        close!
         | 
| 36 | 
            +
                      end
         | 
| 37 | 
            +
                    end
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
             | 
| 10 40 | 
             
                  def initialize(**opts)
         | 
| 11 41 | 
             
                    super(**opts.dup)
         | 
| 12 42 | 
             
                    @files = {}
         | 
| @@ -43,18 +73,9 @@ module BFS | |
| 43 73 | 
             
                  # @option opts [String] :content_type Custom content type.
         | 
| 44 74 | 
             
                  # @option opts [Hash] :metadata Metadata key-value pairs.
         | 
| 45 75 | 
             
                  def create(path, encoding: self.encoding, content_type: nil, metadata: nil, **_opts, &block)
         | 
| 46 | 
            -
                     | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
                    entry = Entry.new(io, Time.now, content_type, norm_meta(metadata))
         | 
| 50 | 
            -
                    @files[norm_path(path)] = entry
         | 
| 51 | 
            -
                    return io unless block
         | 
| 52 | 
            -
             | 
| 53 | 
            -
                    begin
         | 
| 54 | 
            -
                      yield(io)
         | 
| 55 | 
            -
                    ensure
         | 
| 56 | 
            -
                      io.close
         | 
| 57 | 
            -
                    end
         | 
| 76 | 
            +
                    Writer.new(encoding: encoding) do |wio|
         | 
| 77 | 
            +
                      @files[norm_path(path)] = Entry.new(wio, Time.now, content_type, norm_meta(metadata))
         | 
| 78 | 
            +
                    end.perform(&block)
         | 
| 58 79 | 
             
                  end
         | 
| 59 80 |  | 
| 60 81 | 
             
                  # Opens an existing file for reading
         | 
    
        data/lib/bfs/helpers.rb
    CHANGED
    
    | @@ -4,19 +4,33 @@ require 'delegate' | |
| 4 4 | 
             
            module BFS
         | 
| 5 5 | 
             
              class TempWriter < DelegateClass(::Tempfile)
         | 
| 6 6 | 
             
                def initialize(name, tempdir: nil, perm: nil, **opts, &closer)
         | 
| 7 | 
            -
                  @closer | 
| 8 | 
            -
             | 
| 9 | 
            -
                   | 
| 10 | 
            -
                   | 
| 7 | 
            +
                  @closer = closer
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  tempfile = ::Tempfile.new(File.basename(name.to_s), tempdir, **opts)
         | 
| 10 | 
            +
                  tempfile.chmod(perm) if perm
         | 
| 11 | 
            +
                  super tempfile
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def perform(&block)
         | 
| 15 | 
            +
                  return self unless block
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  begin
         | 
| 18 | 
            +
                    yield self
         | 
| 19 | 
            +
                    close
         | 
| 20 | 
            +
                  ensure
         | 
| 21 | 
            +
                    close!
         | 
| 22 | 
            +
                  end
         | 
| 11 23 | 
             
                end
         | 
| 12 24 |  | 
| 13 25 | 
             
                def close
         | 
| 14 26 | 
             
                  return if closed?
         | 
| 15 27 |  | 
| 16 | 
            -
                   | 
| 17 | 
            -
                   | 
| 18 | 
            -
                  @closer&.call(path)
         | 
| 19 | 
            -
                   | 
| 28 | 
            +
                  tempfile = __getobj__
         | 
| 29 | 
            +
                  tempfile.close
         | 
| 30 | 
            +
                  @closer&.call(tempfile.path)
         | 
| 31 | 
            +
                  true
         | 
| 32 | 
            +
                ensure
         | 
| 33 | 
            +
                  tempfile.unlink
         | 
| 20 34 | 
             
                end
         | 
| 21 35 | 
             
              end
         | 
| 22 36 | 
             
            end
         | 
    
        data/spec/bfs/helpers_spec.rb
    CHANGED
    
    | @@ -19,4 +19,9 @@ RSpec.describe BFS::TempWriter, core: true do | |
| 19 19 | 
             
                expect(closer).to receive(:call).with(subject.path)
         | 
| 20 20 | 
             
                expect(subject.close).to be_truthy
         | 
| 21 21 | 
             
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              it 'may skip closer block' do
         | 
| 24 | 
            +
                expect(closer).not_to receive(:call)
         | 
| 25 | 
            +
                expect(subject.close!).to be_truthy
         | 
| 26 | 
            +
              end
         | 
| 22 27 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: bfs
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.7. | 
| 4 | 
            +
              version: 0.7.5
         | 
| 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 | 
            +
            date: 2020-11-02 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 13 | 
             
            description: Minimalist abstraction for bucket storage
         | 
| 14 14 | 
             
            email: dimitrij@blacksquaremedia.com
         |