Class: SitemapGenerator::GoogleStorageAdapter
- Inherits:
-
Object
- Object
- SitemapGenerator::GoogleStorageAdapter
- 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
-
#initialize(opts = {}) ⇒ GoogleStorageAdapter
constructor
Requires Google::Cloud::Storage to be defined.
-
#write(location, raw_data) ⇒ Object
Call with a SitemapLocation and string data.
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:
25 26 27 28 29 30 |
# File 'lib/sitemap_generator/adapters/google_storage_adapter.rb', line 25 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
33 34 35 36 37 38 39 |
# File 'lib/sitemap_generator/adapters/google_storage_adapter.rb', line 33 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 |