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.

Constant Summary collapse

DEFAULT_SIZE =
'100%'

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Attachment.



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

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

Instance Method Details

#destroyObject



49
50
51
52
53
54
# File 'core/app/models/concerns/spree/active_storage_adapter/attachment.rb', line 49

def destroy
  return false unless attached?

  purge
  true
end

#exists?Boolean

Returns:

  • (Boolean)


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

def exists?
  attached?
end

#filenameObject



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

def filename
  blob.filename.to_s
end

#heightObject



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

def height
  [:height]
end

#url(style = nil) ⇒ Object



27
28
29
# File 'core/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 'core/app/models/concerns/spree/active_storage_adapter/attachment.rb', line 31

def variant(style = nil)
  size = style_to_size(style&.to_sym)
  @attachment.variant(
    resize: size,
    strip: true,
    'auto-orient': true,
    colorspace: 'sRGB',
  ).processed
end

#widthObject



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

def width
  [:width]
end