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
103 def url(version = nil, **options)
104   attachment = get
105 
106   if attachment.is_a?(Hash)
107     if version
108       version = version.to_sym
109       if attachment.key?(version)
110         attachment[version].url(**options)
111       elsif fallback = shrine_class.version_fallbacks[version]
112         url(fallback, **options)
113       else
114         default_url(**options, version: version)
115       end
116     else
117       raise Error, "must call Shrine::Attacher#url with the name of the version"
118     end
119   else
120     if version
121       if attachment && fallback_to_original?
122         attachment.url(**options)
123       else
124         default_url(**options, version: version)
125       end
126     else
127       super(**options)
128     end
129   end
130 end