Class: Ratonvirus::Storage::Carrierwave

Inherits:
Base
  • Object
show all
Defined in:
lib/ratonvirus/storage/carrierwave.rb

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#initialize, #process

Constructor Details

This class inherits a constructor from Ratonvirus::Storage::Base

Instance Method Details

#accept?(resource) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
# File 'lib/ratonvirus/storage/carrierwave.rb', line 10

def accept?(resource)
  if resource.is_a?(Array)
    resource.all? { |subr| subr.is_a?(::CarrierWave::Uploader::Base) }
  else
    resource.is_a?(::CarrierWave::Uploader::Base)
  end
end

#asset_path(asset) {|asset.file.path| ... } ⇒ Object

Yields:

  • (asset.file.path)


18
19
20
21
22
23
24
# File 'lib/ratonvirus/storage/carrierwave.rb', line 18

def asset_path(asset)
  return unless block_given?
  return if asset.nil?
  return if asset.file.nil?

  yield asset.file.path
end

#asset_remove(asset) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/ratonvirus/storage/carrierwave.rb', line 26

def asset_remove(asset)
  path = asset.file.path
  asset.remove!

  # Remove the temp cache dir if it exists
  dir = File.dirname(path)
  FileUtils.remove_dir(dir) if File.directory?(dir)
end

#changed?(record, attribute) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/ratonvirus/storage/carrierwave.rb', line 6

def changed?(record, attribute)
  record.public_send :"#{attribute}_changed?"
end