Class: Roundup
- Inherits:
-
Object
- Object
- Roundup
- 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
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#policy ⇒ Object
readonly
Returns the value of attribute policy.
-
#scanner ⇒ Object
readonly
Returns the value of attribute scanner.
Instance Method Summary collapse
- #clean! ⇒ Object
- #files_to_keep ⇒ Object
- #files_to_remove ⇒ Object
-
#initialize(path, options = {}) ⇒ Roundup
constructor
A new instance of Roundup.
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, = {} @path = path @dryrun = .fetch(:dryrun, true) @verbose = .fetch(:verbose, false) @policy = .fetch(:policy, DEFAULT_POLICY) @scanner = .fetch(:scanner, Scanner).new(path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/roundup.rb', line 7 def path @path end |
#policy ⇒ Object (readonly)
Returns the value of attribute policy.
7 8 9 |
# File 'lib/roundup.rb', line 7 def policy @policy end |
#scanner ⇒ Object (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_keep ⇒ Object
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_remove ⇒ Object
21 22 23 |
# File 'lib/roundup.rb', line 21 def files_to_remove files - files_to_keep end |