Skip to content

Commit

Permalink
Merge pull request #4003 from nebulab/nebulab/active-storage-variant-…
Browse files Browse the repository at this point in the history
…syntax

Switch to the correct ActiveStorage variant syntax
  • Loading branch information
kennyadsl authored Apr 14, 2021
2 parents e878076 + 0b3a069 commit 2addfd6
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions core/app/models/concerns/spree/active_storage_adapter/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,28 @@ module ActiveStorageAdapter
class Attachment
delegate_missing_to :@attachment

DEFAULT_SIZE = '100%'

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

def exists?
attached?
end

def filename
blob.filename.to_s
blob&.filename.to_s
end

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

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

Expand All @@ -61,8 +57,12 @@ def metadata
@attachment.metadata
end

def normalize_styles(styles)
styles.transform_values { |v| v.split('x') }
end

def style_to_size(style)
@styles.fetch(style) { DEFAULT_SIZE }
@styles.fetch(style&.to_sym) { [width, height] }
end
end
end
Expand Down

0 comments on commit 2addfd6

Please sign in to comment.