Class: Alchemy::StorageAdapter::Dragonfly::PictureUrl

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

Constant Summary collapse

TRANSFORMATION_OPTIONS =
[
  :crop,
  :crop_from,
  :crop_size,
  :flatten,
  :format,
  :quality,
  :size,
  :upsample
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(picture) ⇒ PictureUrl

Returns a new instance of PictureUrl.

Parameters:



21
22
23
# File 'app/models/alchemy/storage_adapter/dragonfly/picture_url.rb', line 21

def initialize(picture)
  @picture = picture
end

Instance Attribute Details

#pictureObject (readonly)

Returns the value of attribute picture.



17
18
19
# File 'app/models/alchemy/storage_adapter/dragonfly/picture_url.rb', line 17

def picture
  @picture
end

#thumbObject (readonly)

Returns the value of attribute thumb.



17
18
19
# File 'app/models/alchemy/storage_adapter/dragonfly/picture_url.rb', line 17

def thumb
  @thumb
end

#variantObject (readonly)

Returns the value of attribute variant.



17
18
19
# File 'app/models/alchemy/storage_adapter/dragonfly/picture_url.rb', line 17

def variant
  @variant
end

Instance Method Details

#call(options = {}) ⇒ String

The URL to a variant of a picture

Returns:

  • (String)


29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/alchemy/storage_adapter/dragonfly/picture_url.rb', line 29

def call(options = {})
  @variant = PictureVariant.new(picture, options.slice(*TRANSFORMATION_OPTIONS))
  params = {
    basename: picture.name,
    ext: variant.render_format,
    name: picture.name
  }

  return variant.image.url(params) unless processible_image?

  "/#{uid}"
end