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