Class: CarrierWave::Storage::File

Inherits:
Abstract
  • Object
show all
Defined in:
lib/carrierwave/storage/file.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#identifier, #path, setup!, #url

Constructor Details

#initialize(uploader) ⇒ File

Returns a new instance of File.



5
6
7
# File 'lib/carrierwave/storage/file.rb', line 5

def initialize(uploader)
  @uploader = uploader
end

Class Method Details

.retrieve!(uploader, identifier) ⇒ CarrierWave::SanitizedFile

Retrieve the file from its store path

Parameters:

  • uploader (CarrierWave::Uploader)

    an uploader object

  • identifier (String)

    the filename of the file

Returns:



32
33
34
35
36
# File 'lib/carrierwave/storage/file.rb', line 32

def self.retrieve!(uploader, identifier)
  path = ::File.join(uploader.store_dir, identifier)
  path = ::File.expand_path(path, uploader.public)
  CarrierWave::SanitizedFile.new(path)
end

.store!(uploader, file) ⇒ CarrierWave::SanitizedFile

Move the file to the uploader’s store path.

Parameters:

Returns:



17
18
19
20
21
22
# File 'lib/carrierwave/storage/file.rb', line 17

def self.store!(uploader, file)
  path = ::File.join(uploader.store_dir, uploader.filename)
  path = ::File.expand_path(path, uploader.public)
  file.move_to(path)
  file
end