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
rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(key: :sitemap, filename: 'sitemap.xml.gz') ⇒ ActiveStorageAdapter
Returns a new instance of ActiveStorageAdapter.
8 9 10 11 |
# File 'lib/sitemap_generator/adapters/active_storage_adapter.rb', line 8 def initialize(key: :sitemap, filename: 'sitemap.xml.gz') @key = key @filename = filename end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
6 7 8 |
# File 'lib/sitemap_generator/adapters/active_storage_adapter.rb', line 6 def filename @filename end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/sitemap_generator/adapters/active_storage_adapter.rb', line 6 def key @key end |
Instance Method Details
#write(location, raw_data) ⇒ Object
rubocop:disable Metrics/MethodLength
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sitemap_generator/adapters/active_storage_adapter.rb', line 13 def write(location, raw_data) # rubocop:disable Metrics/MethodLength SitemapGenerator::FileAdapter.new.write(location, raw_data) ActiveStorage::Blob.transaction do ActiveStorage::Blob.where(key: key).destroy_all File.open(location.path, 'rb') do |io| ActiveStorage::Blob.create_and_upload!( key: key, io: io, filename: filename, content_type: 'application/gzip', identify: false ) end end end |