Module: CarrierWave::Uploader::Store::ClassMethods
- Defined in:
- lib/carrierwave/uploader/store.rb
Instance Method Summary collapse
-
#storage(storage = nil) ⇒ Object
(also: #storage=)
Sets the storage engine to be used when storing files with this uploader.
Instance Method Details
#storage(storage = nil) ⇒ Object Also known as: storage=
Sets the storage engine to be used when storing files with this uploader. Can be any class that implements a #store!(CarrierWave::SanitizedFile) and a #retrieve! method. See lib/carrierwave/storage/file.rb for an example. Storage engines should be added to CarrierWave.config so they can be referred to by a symbol, which should be more convenient
If no argument is given, it will simply return the currently used storage engine.
Parameters
- storage (Symbol, Class)
-
The storage engine to use for this uploader
Returns
- Class
-
the storage engine to be used with this uploader
Examples
storage :file
storage CarrierWave::Storage::File
storage MyCustomStorageEngine
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/carrierwave/uploader/store.rb', line 36 def storage(storage = nil) if storage.is_a?(Symbol) @storage = get_storage_by_symbol(storage) @storage.setup! elsif storage @storage = storage @storage.setup! elsif @storage.nil? # Get the storage from the superclass if there is one @storage = superclass.storage rescue nil end if @storage.nil? # If we were not able to find a store any other way, setup the default store @storage ||= get_storage_by_symbol(CarrierWave.config[:storage]) @storage.setup! end return @storage end |