Sha256: be07c46fc0aa9e3f8134074ae976b4bfae1b67a301f23fd299b4a482281549a7

Contents?: true

Size: 1007 Bytes

Versions: 66

Compression:

Stored size: 1007 Bytes

Contents

# frozen_string_literal: true

module Alchemy
  class Attachment < BaseRecord
    # The class representing an URL to an attachment
    #
    # Set a different one
    #
    #     Alchemy::Attachment.url_class = MyRemoteUrlClass
    #
    class Url
      def initialize(attachment)
        @attachment = attachment
      end

      # The attachment url
      #
      # @param [Hash] options
      # @option options [Symbol] :download return a URL for downloading the attachment
      # @option options [Symbol] :name The filename
      # @option options [Symbol] :format The file extension
      #
      # @return [String]
      #
      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

      private

      def routes
        Alchemy::Engine.routes.url_helpers
      end
    end
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
alchemy_cms-7.0.8 app/models/alchemy/attachment/url.rb
alchemy_cms-7.0.7 app/models/alchemy/attachment/url.rb
alchemy_cms-7.0.6 app/models/alchemy/attachment/url.rb
alchemy_cms-7.0.5 app/models/alchemy/attachment/url.rb
alchemy_cms-7.0.4 app/models/alchemy/attachment/url.rb
alchemy_cms-7.0.3 app/models/alchemy/attachment/url.rb
alchemy_cms-6.1.9 app/models/alchemy/attachment/url.rb
alchemy_cms-7.0.2 app/models/alchemy/attachment/url.rb
alchemy_cms-6.1.8 app/models/alchemy/attachment/url.rb
alchemy_cms-6.1.7 app/models/alchemy/attachment/url.rb
alchemy_cms-7.0.1 app/models/alchemy/attachment/url.rb
alchemy_cms-7.0.0 app/models/alchemy/attachment/url.rb
alchemy_cms-7.0.0.pre.rc1 app/models/alchemy/attachment/url.rb
alchemy_cms-6.1.6 app/models/alchemy/attachment/url.rb
alchemy_cms-7.0.0.pre.c app/models/alchemy/attachment/url.rb
alchemy_cms-7.0.0.pre.b app/models/alchemy/attachment/url.rb
alchemy_cms-6.1.5 app/models/alchemy/attachment/url.rb
alchemy_cms-6.0.14 app/models/alchemy/attachment/url.rb
alchemy_cms-6.1.4 app/models/alchemy/attachment/url.rb
alchemy_cms-7.0.0.pre.a app/models/alchemy/attachment/url.rb