Sha256: b5bd17d253f0ab44f5bc3dccb058d27c2b002ec16bc6a602b6a3970cc2e02af0

Contents?: true

Size: 1.4 KB

Versions: 15

Compression:

Stored size: 1.4 KB

Contents

module Fog
  module Storage
    class GoogleJSON
      class Directories < Fog::Collection
        model Fog::Storage::GoogleJSON::Directory

        def all(opts = {})
          data = service.list_buckets(**opts).to_h[:items] || []
          load(data)
        end

        def get(bucket_name, options = {})
          if_metageneration_match = options[:if_metageneration_match]
          if_metageneration_not_match = options[:if_metageneration_not_match]
          projection = options[:projection]

          data = service.get_bucket(
            bucket_name,
            :if_metageneration_match => if_metageneration_match,
            :if_metageneration_not_match => if_metageneration_not_match,
            :projection => projection
          ).to_h

          directory = new(data)
          # Because fog-aws accepts these arguments on files at the
          # directories.get level, we need to preload the directory files
          # with these attributes here.
          files_attr_names = %i(delimiter page_token max_results prefix)

          file_opts = options.select { |k, _| files_attr_names.include? k }
          directory.files(file_opts)
          directory
        rescue ::Google::Apis::ClientError => e
          # metageneration check failures returns HTTP 412 Precondition Failed
          raise e unless e.status_code == 404 || e.status_code == 412
          nil
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
fog-google-1.24.1 lib/fog/storage/google_json/models/directories.rb
fog-google-1.24.0 lib/fog/storage/google_json/models/directories.rb
fog-google-1.23.0 lib/fog/storage/google_json/models/directories.rb
fog-google-1.22.0 lib/fog/storage/google_json/models/directories.rb
fog-google-1.21.1 lib/fog/storage/google_json/models/directories.rb
fog-google-1.21.0 lib/fog/storage/google_json/models/directories.rb
fog-google-1.20.0 lib/fog/storage/google_json/models/directories.rb
fog-google-1.19.0 lib/fog/storage/google_json/models/directories.rb
fog-google-1.18.0 lib/fog/storage/google_json/models/directories.rb
fog-google-1.17.0 lib/fog/storage/google_json/models/directories.rb
fog-google-1.16.1 lib/fog/storage/google_json/models/directories.rb
fog-google-1.16.0 lib/fog/storage/google_json/models/directories.rb
fog-google-1.15.0 lib/fog/storage/google_json/models/directories.rb
fog-google-1.14.0 lib/fog/storage/google_json/models/directories.rb
gitlab-fog-google-1.14.0 lib/fog/storage/google_json/models/directories.rb