module Shrine::Plugins::Versions::AttacherMethods

  1. lib/shrine/plugins/versions.rb

Methods

Public Instance

  1. data
  2. destroy
  3. file=
  4. uploaded_file
  5. url

Public Instance methods

data()

Converts the Hash/Array of UploadedFile objects into a Hash/Array of data.

[show source]
   # File lib/shrine/plugins/versions.rb
90 def data
91   Utils.map_file(file, transform_keys: :to_s) do |_, version|
92     version.data
93   end
94 end
destroy(*)
[show source]
   # File lib/shrine/plugins/versions.rb
56 def destroy(*)
57   Utils.each_file(self.file) { |_, file| file.delete }
58 end
file=(file)
[show source]
    # File lib/shrine/plugins/versions.rb
 96 def file=(file)
 97   if file.is_a?(Hash) || file.is_a?(Array)
 98     @file = file
 99   else
100     super
101   end
102 end
uploaded_file(value, &block)
[show source]
    # File lib/shrine/plugins/versions.rb
104 def uploaded_file(value, &block)
105   shrine_class.uploaded_file(value, &block)
106 end
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
62 def url(version = nil, **options)
63   if file.is_a?(Hash)
64     if version
65       version = version.to_sym
66       if file.key?(version)
67         file[version].url(**options)
68       elsif fallback = shrine_class.version_fallbacks[version]
69         url(fallback, **options)
70       else
71         default_url(**options, version: version)
72       end
73     else
74       raise Error, "must call Shrine::Attacher#url with the name of the version"
75     end
76   else
77     if version
78       if file && shrine_class.opts[:versions][:fallback_to_original]
79         file.url(**options)
80       else
81         default_url(**options, version: version)
82       end
83     else
84       super(**options)
85     end
86   end
87 end