Class: SitemapGenerator::ActiveStorageAdapter
- Inherits:
-
Object
- Object
- SitemapGenerator::ActiveStorageAdapter
- Defined in:
- lib/sitemap_generator/adapters/active_storage_adapter.rb
Overview
Class for uploading sitemaps to ActiveStorage.
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(key: :sitemap, filename: 'sitemap.xml.gz') ⇒ ActiveStorageAdapter
constructor
A new instance of ActiveStorageAdapter.
- #write(location, raw_data) ⇒ Object
Constructor Details
#initialize(key: :sitemap, filename: 'sitemap.xml.gz') ⇒ ActiveStorageAdapter
Returns a new instance of ActiveStorageAdapter.
6 7 8 |
# File 'lib/sitemap_generator/adapters/active_storage_adapter.rb', line 6 def initialize key: :sitemap, filename: 'sitemap.xml.gz' @key, @filename = key, filename end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
4 5 6 |
# File 'lib/sitemap_generator/adapters/active_storage_adapter.rb', line 4 def filename @filename end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
4 5 6 |
# File 'lib/sitemap_generator/adapters/active_storage_adapter.rb', line 4 def key @key end |
Instance Method Details
#write(location, raw_data) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sitemap_generator/adapters/active_storage_adapter.rb', line 10 def write(location, raw_data) SitemapGenerator::FileAdapter.new.write(location, raw_data) ActiveStorage::Blob.transaction do ActiveStorage::Blob.where(key: key).destroy_all ActiveStorage::Blob.create_and_upload!( key: key, io: open(location.path, 'rb'), filename: filename, content_type: 'application/gzip', identify: false ) end end |