Class: Ratonvirus::Storage::Filepath

Inherits:
Base
  • Object
show all
Defined in:
lib/ratonvirus/storage/filepath.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)


15
16
17
18
19
20
21
# 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| ... } ⇒ Object

Yields:

  • (asset)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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) ⇒ Object



41
42
43
# File 'lib/ratonvirus/storage/filepath.rb', line 41

def asset_remove(asset)
  FileUtils.remove_file(asset) if File.file?(asset)
end

#changed?(record, attribute) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
# 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