module Shrine::Plugins::Versions::AttacherMethods
Public Instance Methods
data()
click to toggle source
Converts the Hash/Array of UploadedFile
objects into a Hash/Array of data.
# File lib/shrine/plugins/versions.rb, line 90 def data Utils.map_file(file, transform_keys: :to_s) do |_, version| version.data end end
destroy(*)
click to toggle source
# File lib/shrine/plugins/versions.rb, line 56 def destroy(*) Utils.each_file(self.file) { |_, file| file.delete } end
file=(file)
click to toggle source
Calls superclass method
# File lib/shrine/plugins/versions.rb, line 96 def file=(file) if file.is_a?(Hash) || file.is_a?(Array) @file = file else super end end
uploaded_file(value, &block)
click to toggle source
# File lib/shrine/plugins/versions.rb, line 104 def uploaded_file(value, &block) shrine_class.uploaded_file(value, &block) end
url(version = nil, **options)
click to toggle source
Smart versioned URLs, which include the version name in the default URL, and properly forwards any options to the underlying storage.
Calls superclass method
# File lib/shrine/plugins/versions.rb, line 62 def url(version = nil, **options) if file.is_a?(Hash) if version version = version.to_sym if file.key?(version) file[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 file && shrine_class.opts[:versions][:fallback_to_original] file.url(**options) else default_url(**options, version: version) end else super(**options) end end end
Private Instance Methods
uploaded?(file, storage_key)
click to toggle source
Calls superclass method
# File lib/shrine/plugins/versions.rb, line 110 def uploaded?(file, storage_key) if file.is_a?(Hash) || file.is_a?(Array) Utils.each_file(file).all? { |_, f| f.storage_key == storage_key } else super end end