Class: Alchemy::Attachment::Url

Inherits:
Object
  • Object
show all
Defined in:
app/models/alchemy/attachment/url.rb

Overview

The class representing an URL to an attachment

Set a different one

Alchemy::Attachment.url_class = MyRemoteUrlClass

Instance Method Summary collapse

Constructor Details

#initialize(attachment) ⇒ Url

Returns a new instance of Url.



12
13
14
# File 'app/models/alchemy/attachment/url.rb', line 12

def initialize(attachment)
  @attachment = attachment
end

Instance Method Details

#call(options = {}) ⇒ String

The attachment url

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :download (Symbol)

    return a URL for downloading the attachment

  • :name (Symbol)

    The filename

  • :format (Symbol)

    The file extension

Returns:

  • (String)


25
26
27
28
29
30
31
32
# File 'app/models/alchemy/attachment/url.rb', line 25

def call(options = {})
  options[:format] ||= @attachment.suffix
  if options.delete(:download)
    routes.download_attachment_path(@attachment, options)
  else
    routes.show_attachment_path(@attachment, options)
  end
end