Class: Roundup

Inherits:
Object
  • Object
show all
Defined in:
lib/roundup.rb

Defined Under Namespace

Classes: Scanner

Constant Summary collapse

DEFAULT_POLICY =
{:hourly => 48, :daily => 31, :monthly => 12}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Roundup

Returns a new instance of Roundup.



9
10
11
12
13
14
15
# File 'lib/roundup.rb', line 9

def initialize path, options = {}
  @path    = path
  @dryrun  = options.fetch(:dryrun,  true)
  @verbose = options.fetch(:verbose, false)
  @policy  = options.fetch(:policy,  DEFAULT_POLICY)
  @scanner = options.fetch(:scanner, Scanner).new(path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/roundup.rb', line 7

def path
  @path
end

#policyObject (readonly)

Returns the value of attribute policy.



7
8
9
# File 'lib/roundup.rb', line 7

def policy
  @policy
end

#scannerObject (readonly)

Returns the value of attribute scanner.



7
8
9
# File 'lib/roundup.rb', line 7

def scanner
  @scanner
end

Instance Method Details

#clean!Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/roundup.rb', line 25

def clean!
  remove = files_to_remove

  info 'deleting %d files' % remove.count
  info remove.join($/) unless remove.empty?

  if dryrun?
    info 'dry run - so nothing deleted'
  else
    FileUtils.rm_f(remove)
    info 'cleaned!'
  end
end

#files_to_keepObject



17
18
19
# File 'lib/roundup.rb', line 17

def files_to_keep
  policy.map {|interval, n| scanner.find(interval).take(n)}.flatten.uniq
end

#files_to_removeObject



21
22
23
# File 'lib/roundup.rb', line 21

def files_to_remove
  files - files_to_keep
end