Sha256: 2636474a9134eb6b75d0563812bdffb4c279ddfce68de7dc5d01d6ade9c7cb7a

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 KB

Contents

module CarrierWave
  module Storage

    ##
    # File storage stores file to the Filesystem (surprising, no?). There's really not much
    # to it, it uses the store_dir defined on the uploader as the storage location. That's
    # pretty much it.
    #
    class File < Abstract
      
      def initialize(uploader)
        @uploader = uploader
      end
      
      ##
      # Move the file to the uploader's store path.
      #
      # === Parameters
      #
      # [uploader (CarrierWave::Uploader)] an uploader object
      # [file (CarrierWave::SanitizedFile)] the file to store
      #
      # === Returns
      #
      # [CarrierWave::SanitizedFile] a sanitized file
      #
      def self.store!(uploader, file)
        path = ::File.join(uploader.store_path)
        path = ::File.expand_path(path, uploader.public)
        file.move_to(path, CarrierWave.config[:permissions])
        file
      end
      
      ##
      # Retrieve the file from its store path
      #
      # === Parameters
      #
      # [uploader (CarrierWave::Uploader)] an uploader object
      # [identifier (String)] the filename of the file
      #
      # === Returns
      #
      # [CarrierWave::SanitizedFile] a sanitized file
      #
      def self.retrieve!(uploader, identifier)
        path = ::File.join(uploader.store_path(identifier))
        path = ::File.expand_path(path, uploader.public)
        CarrierWave::SanitizedFile.new(path)
      end
      
    end # File
  end # Storage
end # CarrierWave

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
jnicklas-carrierwave-0.2.0 lib/carrierwave/storage/file.rb
jnicklas-carrierwave-0.2.1 lib/carrierwave/storage/file.rb
jnicklas-carrierwave-0.2.2 lib/carrierwave/storage/file.rb
carrierwave-0.2.0 lib/carrierwave/storage/file.rb
carrierwave-0.2.1 lib/carrierwave/storage/file.rb