Class: Alchemy::StorageAdapter::ActiveStorage::PictureUrl

Inherits:
Object
  • Object
show all
Defined in:
app/models/alchemy/storage_adapter/active_storage/picture_url.rb

Overview

Returns the URL to a variant of a picture using ActiveStorage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(picture) ⇒ PictureUrl

Returns a new instance of PictureUrl.

Parameters:



11
12
13
14
# File 'app/models/alchemy/storage_adapter/active_storage/picture_url.rb', line 11

def initialize(picture)
  @picture = picture
  @image_file = picture.image_file
end

Instance Attribute Details

#image_fileObject (readonly)

Returns the value of attribute image_file.



7
8
9
# File 'app/models/alchemy/storage_adapter/active_storage/picture_url.rb', line 7

def image_file
  @image_file
end

#pictureObject (readonly)

Returns the value of attribute picture.



7
8
9
# File 'app/models/alchemy/storage_adapter/active_storage/picture_url.rb', line 7

def picture
  @picture
end

Instance Method Details

#call(options = {}) ⇒ String

The URL to a variant of a picture

Returns:

  • (String)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/alchemy/storage_adapter/active_storage/picture_url.rb', line 20

def call(options = {})
  variant_options = DragonflyToImageProcessing.call(options)
  variant_options[:format] = options[:format] || default_output_format
  variant = image_file&.variant(variant_options)
  return unless variant

  Rails.application.routes.url_helpers.rails_blob_path(
    variant,
    {
      filename: filename(options),
      format: variant_options[:format],
      only_path: true
    }
  )
end