Class: SitemapGenerator::GoogleStorageAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/sitemap_generator/adapters/google_storage_adapter.rb

Overview

Class for uploading sitemaps to a Google Storage using `google-cloud-storage` gem.

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ GoogleStorageAdapter

Requires Google::Cloud::Storage to be defined.

All options other than the `:bucket` option are passed to the `Google::Cloud::Storage.new` initializer. See googleapis.dev/ruby/google-cloud-storage/latest/file.AUTHENTICATION.html for all the supported environment variables and github.com/googleapis/google-cloud-ruby/blob/master/google-cloud-storage/lib/google/cloud/storage.rb for supported options.

Suggested Options:

Parameters:

  • opts (Hash) (defaults to: {})

    Google::Cloud::Storage configuration options.

  • :bucket (Hash)

    a customizable set of options

  • :credentials (Hash)

    a customizable set of options

  • :project_id (Hash)

    a customizable set of options


22
23
24
25
26
# File 'lib/sitemap_generator/adapters/google_storage_adapter.rb', line 22

def initialize(opts = {})
  opts = opts.clone
  @bucket = opts.delete(:bucket)
  @storage_options = opts
end

Instance Method Details

#write(location, raw_data) ⇒ Object

Call with a SitemapLocation and string data


29
30
31
32
33
34
35
# File 'lib/sitemap_generator/adapters/google_storage_adapter.rb', line 29

def write(location, raw_data)
  SitemapGenerator::FileAdapter.new.write(location, raw_data)

  storage = Google::Cloud::Storage.new(@storage_options)
  bucket = storage.bucket(@bucket)
  bucket.create_file(location.path, location.path_in_public, acl: 'public')
end