module Shrine::Plugins::Versions::AttacherMethods

  1. lib/shrine/plugins/versions.rb

Methods

Public Instance

  1. url

Public Instance methods

url (version = nil, **options)

Smart versioned URLs, which include the version name in the default URL, and properly forwards any options to the underlying storage.

[show source]
# File lib/shrine/plugins/versions.rb, line 208
def url(version = nil, **options)
  attachment = get

  if attachment.is_a?(Hash)
    if version
      if attachment.key?(version)
        attachment[version].url(**options)
      elsif fallback = shrine_class.version_fallbacks[version]
        url(fallback, **options)
      else
        default_url(**options, version: version)
      end
    else
      raise Error, "must call Shrine::Attacher#url with the name of the version"
    end
  else
    if version
      if attachment && fallback_to_original?
        attachment.url(**options)
      else
        default_url(**options, version: version)
      end
    else
      super(**options)
    end
  end
end