class Ratonvirus::Storage::Filepath

Public Instance Methods

accept?(resource) click to toggle source
# File lib/ratonvirus/storage/filepath.rb, line 15
def accept?(resource)
  if resource.is_a?(Array)
    resource.all? { |r| r.is_a?(String) || r.is_a?(File) }
  else
    resource.is_a?(String) || resource.is_a?(File)
  end
end
asset_path(asset) { |asset| ... } click to toggle source
# File lib/ratonvirus/storage/filepath.rb, line 23
def asset_path(asset, &block)
  return unless block_given?

  return unless asset
  return if asset.empty?

  if asset.respond_to?(:path)
    # A file asset that responds to path (e.g. default `File`
    # object).
    asset_path(asset.path, &block)

    return
  end

  # Plain file path string provided as resource
  yield asset
end
asset_remove(asset) click to toggle source
# File lib/ratonvirus/storage/filepath.rb, line 41
def asset_remove(asset)
  FileUtils.remove_file(asset) if File.file?(asset)
end
changed?(record, attribute) click to toggle source
# File lib/ratonvirus/storage/filepath.rb, line 6
def changed?(record, attribute)
  return record.public_send :"#{attribute}_changed?" if record.respond_to? :"#{attribute}_changed?"

  # Some backends do not implement the `attribute_changed?` methods for
  # the file resources. In that case our best guess is to check whether
  # the whole record has changed.
  record.changed?
end