Module: Shrine::Plugins::UrlsafeSerialization::FileMethods

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

Instance Method Summary collapse

Instance Method Details

#urlsafe_data(metadata: []) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/shrine/plugins/_urlsafe_serialization.rb', line 30

def urlsafe_data(metadata: [])
  data = self.data.dup

  if .any?
    # order metadata in the specified order
    data["metadata"] = 
      .map { |name| [name, self.[name]] }
      .to_h
  else
    # save precious characters
    data.delete("metadata")
  end

  data
end

#urlsafe_dump(**options) ⇒ Object


26
27
28
# File 'lib/shrine/plugins/_urlsafe_serialization.rb', line 26

def urlsafe_dump(**options)
  self.class.urlsafe_dump(self, **options)
end