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` and `:acl` options 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

  • :acl (Hash)

    a customizable set of options

  • :credentials (Hash)

    a customizable set of options

  • :project_id (Hash)

    a customizable set of options



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

def initialize(opts = {})
  opts = opts.clone
  @bucket = opts.delete(:bucket)
  @acl = opts.has_key?(:acl) ? opts.delete(:acl) : 'public'
  @storage_options = opts
end

Instance Method Details

#write(location, raw_data) ⇒ Object

Call with a SitemapLocation and string data



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

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: @acl)
end