lib/attached/attachment.rb in attached-0.5.3 vs lib/attached/attachment.rb in attached-0.5.4

- old
+ new

@@ -1,5 +1,7 @@ +require 'open-uri' + require 'identifier' require 'attached/storage' require 'attached/storage/error' @@ -170,9 +172,27 @@ self.size = file ? size : nil self.extension = file ? extension : nil self.identifier = file ? identifier : nil process if file + end + + + # Assign an attachment to a file. + # + # Usage: + # + # @object.avatar.url = "https://.../file" + + def url=(url) + extension = File.extname(url) + + file = Tempfile.new(["", extension]) + file.binmode + + file << open(url).read + + self.assign(file) end # Save an attachment. # \ No newline at end of file