/lib/carrierwave/uploader/download.rb

http://github.com/jnicklas/carrierwave · Ruby · 24 lines · 14 code · 2 blank · 8 comment · 0 complexity · 814523594ca0390544b366a1f4388120 MD5 · raw file

  1. module CarrierWave
  2. module Uploader
  3. module Download
  4. extend ActiveSupport::Concern
  5. include CarrierWave::Uploader::Callbacks
  6. include CarrierWave::Uploader::Configuration
  7. include CarrierWave::Uploader::Cache
  8. ##
  9. # Caches the file by downloading it from the given URL, using downloader.
  10. #
  11. # === Parameters
  12. #
  13. # [url (String)] The URL where the remote file is stored
  14. # [remote_headers (Hash)] Request headers
  15. #
  16. def download!(uri, remote_headers = {})
  17. file = downloader.new(self).download(uri, remote_headers)
  18. cache!(file)
  19. end
  20. end # Download
  21. end # Uploader
  22. end # CarrierWave