Class: ImageKitIo::CarrierWave::Storage::ImageKitStore
- Inherits:
-
CarrierWave::Storage::Abstract
- Object
- CarrierWave::Storage::Abstract
- ImageKitIo::CarrierWave::Storage::ImageKitStore
- Defined in:
- lib/carrierwave/storage/imagekit_store.rb
Instance Method Summary collapse
- #cache!(new_file) ⇒ Object
- #clean_cache!(seconds) ⇒ Object
- #delete_dir!(path) ⇒ Object
-
#initialize ⇒ ImageKitStore
constructor
A new instance of ImageKitStore.
- #retrieve!(identifier) ⇒ Object
- #retrieve_from_cache!(identifier) ⇒ Object
- #store!(file) ⇒ Object
Constructor Details
#initialize ⇒ ImageKitStore
Returns a new instance of ImageKitStore.
10 11 12 13 |
# File 'lib/carrierwave/storage/imagekit_store.rb', line 10 def initialize(*) super @cache_called = nil end |
Instance Method Details
#cache!(new_file) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/carrierwave/storage/imagekit_store.rb', line 24 def cache!(new_file) new_file.move_to(::File.(uploader.cache_path, uploader.root), uploader., uploader., true) rescue Errno::EMLINK, Errno::ENOSPC => e raise(e) if @cache_called @cache_called = true # NOTE: Remove cached files older than 10 minutes clean_cache!(600) cache!(new_file) end |
#clean_cache!(seconds) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/carrierwave/storage/imagekit_store.rb', line 54 def clean_cache!(seconds) Dir.glob(::File.(::File.join(uploader.cache_dir, '*'), CarrierWave.root)).each do |dir| # generate_cache_id returns key formated TIMEINT-PID(-COUNTER)-RND time = dir.scan(/(\d+)-\d+-\d+(?:-\d+)?/).first.map(&:to_i) time = Time.at(*time) if time < (Time.now.utc - seconds) FileUtils.rm_rf(dir) end end end |
#delete_dir!(path) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/carrierwave/storage/imagekit_store.rb', line 40 def delete_dir!(path) if path begin Dir.rmdir(::File.(path, uploader.root)) rescue Errno::ENOENT # Ignore: path does not exist rescue Errno::ENOTDIR # Ignore: path is not a dir rescue Errno::ENOTEMPTY, Errno::EEXIST # Ignore: dir is not empty end end end |
#retrieve!(identifier) ⇒ Object
19 20 21 22 |
# File 'lib/carrierwave/storage/imagekit_store.rb', line 19 def retrieve!(identifier) IKFile.new(identifier) end |
#retrieve_from_cache!(identifier) ⇒ Object
36 37 38 |
# File 'lib/carrierwave/storage/imagekit_store.rb', line 36 def retrieve_from_cache!(identifier) CarrierWave::SanitizedFile.new(::File.(uploader.cache_path(identifier), uploader.root)) end |
#store!(file) ⇒ Object
15 16 17 |
# File 'lib/carrierwave/storage/imagekit_store.rb', line 15 def store!(file) file.delete end |