Sha256: 32ca953494c473cd5f1a2bb70c83f325de2c857fba188469ec443ff18188ad16

Contents?: true

Size: 926 Bytes

Versions: 2

Compression:

Stored size: 926 Bytes

Contents

# frozen_string_literal: true

require "stashify/file"

module Stashify
  class File
    module Google
      module Cloud
        # An implementation for interacting with files in Google Cloud
        # Storage buckets. The constructor needs an instance of
        # Google::Cloud::Storage::Bucket in order to know which bucket
        # to interact with.
        class Storage < Stashify::File
          def initialize(bucket:, path:)
            @bucket = bucket
            super(path: path)
          end

          def contents
            @bucket.file(path).download.string
          end

          def write(contents)
            @bucket.create_file(
              StringIO.new(contents),
              path,
            )
          end

          def delete
            @bucket.file(path).delete
          end

          def exists?
            @bucket.file(path)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stashify-google-cloud-storage-3.1.2 lib/stashify/file/google/cloud/storage.rb
stashify-google-cloud-storage-3.1.1 lib/stashify/file/google/cloud/storage.rb