Module: CarrierWave::Uploader::Store
- Extended by:
- ActiveSupport::Concern
- Includes:
- Cache, Callbacks, Configuration
- Included in:
- Base
- Defined in:
- lib/carrierwave/uploader/store.rb
Instance Method Summary collapse
- #delete_original_file? ⇒ Boolean
-
#filename ⇒ Object
Override this in your Uploader to change the filename.
-
#retrieve_from_store!(identifier) ⇒ Object
Retrieves the file from the storage.
-
#store!(new_file = nil) ⇒ Object
Stores the file by passing it to this Uploader’s storage engine.
-
#store_path(for_file = filename) ⇒ Object
Calculates the path where the file should be stored.
Methods included from Cache
#cache!, #cache_name, #cached?, #retrieve_from_cache!
Methods included from Callbacks
Instance Method Details
#delete_original_file? ⇒ Boolean
30 31 32 |
# File 'lib/carrierwave/uploader/store.rb', line 30 def delete_original_file? @original_file && @original_file.path != @file.path # if the path hasn't changed, no need to delete it end |
#filename ⇒ Object
Override this in your Uploader to change the filename.
Be careful using record ids as filenames. If the filename is stored in the database the record id will be nil when the filename is set. Don’t use record ids unless you understand this limitation.
Do not use the version_name in the filename, as it will prevent versions from being loaded correctly.
Returns
- String
-
a filename
26 27 28 |
# File 'lib/carrierwave/uploader/store.rb', line 26 def filename @filename end |
#retrieve_from_store!(identifier) ⇒ Object
Retrieves the file from the storage.
Parameters
- identifier (String)
-
uniquely identifies the file to retrieve
80 81 82 83 84 |
# File 'lib/carrierwave/uploader/store.rb', line 80 def retrieve_from_store!(identifier) with_callbacks(:retrieve_from_store, identifier) do @file = storage.retrieve!(identifier) end end |
#store!(new_file = nil) ⇒ Object
Stores the file by passing it to this Uploader’s storage engine.
If new_file is omitted, a previously cached file will be stored.
Parameters
- new_file (File, IOString, Tempfile)
-
any kind of file object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/carrierwave/uploader/store.rb', line 59 def store!(new_file=nil) cache!(new_file) if new_file if @file and @cache_id with_callbacks(:store, new_file) do @file = storage.store!(@file) @original_file.delete if self.delete_original_file? @cache_id = nil @original_file = nil end end end |
#store_path(for_file = filename) ⇒ Object
Calculates the path where the file should be stored. If for_file
is given, it will be used as the filename, otherwise CarrierWave::Uploader#filename is assumed.
Parameters
- for_file (String)
-
name of the file <optional>
Returns
- String
-
the store path
46 47 48 |
# File 'lib/carrierwave/uploader/store.rb', line 46 def store_path(for_file=filename) File.join([store_dir, full_filename(for_file)].compact) end |