Class: Spree::ActiveStorageAdapter::Attachment

Inherits:
Object
  • Object
show all
Defined in:
core/app/models/concerns/spree/active_storage_adapter/attachment.rb

Overview

Decorares AtiveStorage attachment to add methods exptected by Solidus' Paperclip-oriented attachment support.

Instance Method Summary collapse

Constructor Details

#initialize(attachment, styles: {}) ⇒ Attachment

Returns a new instance of Attachment.



12
13
14
15
# File 'core/app/models/concerns/spree/active_storage_adapter/attachment.rb', line 12

def initialize(attachment, styles: {})
  @attachment = attachment
  @styles = normalize_styles(styles)
end

Instance Method Details

#destroyObject



45
46
47
48
49
50
# File 'core/app/models/concerns/spree/active_storage_adapter/attachment.rb', line 45

def destroy
  return false unless attached?

  purge
  true
end

#exists?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'core/app/models/concerns/spree/active_storage_adapter/attachment.rb', line 17

def exists?
  attached?
end

#filenameObject



21
22
23
# File 'core/app/models/concerns/spree/active_storage_adapter/attachment.rb', line 21

def filename
  blob&.filename.to_s
end

#heightObject



37
38
39
# File 'core/app/models/concerns/spree/active_storage_adapter/attachment.rb', line 37

def height
  [:height]
end

#url(style = nil) ⇒ Object



25
26
27
# File 'core/app/models/concerns/spree/active_storage_adapter/attachment.rb', line 25

def url(style = nil)
  variant(style)&.url
end

#variant(style = nil) ⇒ Object



29
30
31
32
33
34
35
# File 'core/app/models/concerns/spree/active_storage_adapter/attachment.rb', line 29

def variant(style = nil)
  size = style_to_size(style)
  @attachment.variant(
    resize_to_limit: size,
    strip: true
  ).processed
end

#widthObject



41
42
43
# File 'core/app/models/concerns/spree/active_storage_adapter/attachment.rb', line 41

def width
  [:width]
end