Module: Shrine::Plugins::Versions::AttacherMethods

Defined in:
lib/shrine/plugins/versions.rb

Instance Method Summary collapse

Instance Method Details

#url(version = nil, **options) ⇒ Object

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



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/shrine/plugins/versions.rb', line 103

def url(version = nil, **options)
  attachment = get

  if attachment.is_a?(Hash)
    if version
      version = version.to_sym
      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