class TrashMan::Manager

Public Class Methods

new(provider, options = {}) click to toggle source
# File lib/trashman/manager.rb, line 6
def initialize(provider, options = {})
  @options = options

  @connection = Fog::Storage.new(
    { provider: provider }.merge(options[:credentials])
  )
end

Public Instance Methods

cleanup!() { |file| ... } click to toggle source
# File lib/trashman/manager.rb, line 14
def cleanup!(&block)
  queued_files.each do |file|
    yield(file) if block

    if !options[:dry_run]
      file.destroy
    end
  end

  queued_files.count
end

Private Instance Methods

connection() click to toggle source
# File lib/trashman/manager.rb, line 32
def connection
  @connection
end
container() click to toggle source
# File lib/trashman/manager.rb, line 36
def container
  @container ||= connection.directories.get(options[:container])
end
files() click to toggle source
# File lib/trashman/manager.rb, line 40
def files
  @files ||= begin
    if options[:pattern]
      container.files.select { |file| file.key =~ Regexp.new(options[:pattern]) }
    else
      container.files
    end.sort_by { |file| file.key }
  end
end
options() click to toggle source
# File lib/trashman/manager.rb, line 28
def options
  @options
end
queued_files() click to toggle source
# File lib/trashman/manager.rb, line 50
def queued_files
  files[0...(- options[:keep])]
end