Class: Spree::ActiveStorageAdapter::Attachment
- Inherits:
-
Object
- Object
- Spree::ActiveStorageAdapter::Attachment
- Defined in:
- app/models/concerns/spree/active_storage_adapter/attachment.rb
Overview
Decorates ActiveStorage attachment to add methods expected by Solidus’ Paperclip-oriented attachment support.
Instance Attribute Summary collapse
-
#attachment ⇒ Object
readonly
Returns the value of attribute attachment.
Instance Method Summary collapse
- #destroy ⇒ Object
- #exists? ⇒ Boolean
- #filename ⇒ Object
- #height ⇒ Object
-
#initialize(attachment, styles: {}) ⇒ Attachment
constructor
A new instance of Attachment.
- #url(style = nil) ⇒ Object
- #variant(style = nil) ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(attachment, styles: {}) ⇒ Attachment
Returns a new instance of Attachment.
14 15 16 17 |
# File 'app/models/concerns/spree/active_storage_adapter/attachment.rb', line 14 def initialize(, styles: {}) @attachment = @transformations = styles_to_transformations(styles) end |
Instance Attribute Details
#attachment ⇒ Object (readonly)
Returns the value of attribute attachment.
12 13 14 |
# File 'app/models/concerns/spree/active_storage_adapter/attachment.rb', line 12 def @attachment end |
Instance Method Details
#destroy ⇒ Object
49 50 51 52 53 54 |
# File 'app/models/concerns/spree/active_storage_adapter/attachment.rb', line 49 def destroy return false unless attached? purge true end |
#exists? ⇒ Boolean
19 20 21 |
# File 'app/models/concerns/spree/active_storage_adapter/attachment.rb', line 19 def exists? attached? end |
#filename ⇒ Object
23 24 25 |
# File 'app/models/concerns/spree/active_storage_adapter/attachment.rb', line 23 def filename blob&.filename.to_s end |
#height ⇒ Object
41 42 43 |
# File 'app/models/concerns/spree/active_storage_adapter/attachment.rb', line 41 def height [:height] end |
#url(style = nil) ⇒ Object
27 28 29 |
# File 'app/models/concerns/spree/active_storage_adapter/attachment.rb', line 27 def url(style = nil) variant(style)&.url end |
#variant(style = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'app/models/concerns/spree/active_storage_adapter/attachment.rb', line 31 def variant(style = nil) transformation = @transformations[style] || default_transformation(width, height) @attachment.variant({ saver: { strip: true } }.merge(transformation)).processed end |
#width ⇒ Object
45 46 47 |
# File 'app/models/concerns/spree/active_storage_adapter/attachment.rb', line 45 def width [:width] end |