Class: Mosaico::ActiveStorageBackend
- Inherits:
-
Object
- Object
- Mosaico::ActiveStorageBackend
- Defined in:
- lib/mosaico/active_storage_backend.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#path_prefix ⇒ Object
readonly
Returns the value of attribute path_prefix.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Instance Method Summary collapse
-
#initialize(service, path_prefix) ⇒ ActiveStorageBackend
constructor
A new instance of ActiveStorageBackend.
- #retrieve(file) ⇒ Object
- #store(source, as:) ⇒ Object
- #url_to(file) ⇒ Object
Constructor Details
#initialize(service, path_prefix) ⇒ ActiveStorageBackend
Returns a new instance of ActiveStorageBackend.
5 6 7 8 |
# File 'lib/mosaico/active_storage_backend.rb', line 5 def initialize(service, path_prefix) @service = service @path_prefix = path_prefix end |
Instance Attribute Details
#path_prefix ⇒ Object (readonly)
Returns the value of attribute path_prefix.
3 4 5 |
# File 'lib/mosaico/active_storage_backend.rb', line 3 def path_prefix @path_prefix end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
3 4 5 |
# File 'lib/mosaico/active_storage_backend.rb', line 3 def service @service end |
Instance Method Details
#retrieve(file) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mosaico/active_storage_backend.rb', line 15 def retrieve(file) key = "#{path_prefix}/#{file}" data = @service.download(key) tmp_file = Tempfile.new(file, :encoding => 'ascii-8bit') tmp_file.write(data) tmp_file.close tmp_file.path end |
#store(source, as:) ⇒ Object
10 11 12 13 |
# File 'lib/mosaico/active_storage_backend.rb', line 10 def store(source, as:) key = "#{path_prefix}/#{as}" @service.upload(key, open(source)) end |
#url_to(file) ⇒ Object
26 27 28 29 |
# File 'lib/mosaico/active_storage_backend.rb', line 26 def url_to(file) key = "#{path_prefix}/#{file}" @service.url(key, filename: ActiveStorage::Filename.new(file), expires_in: 1.week, disposition: :inline, content_type: nil) end |