Class: LazyRotator::Set
- Inherits:
-
Object
- Object
- LazyRotator::Set
- Includes:
- Enumerable
- Defined in:
- lib/lazy_rotator/set.rb
Overview
Collects rotated/to-rotate files and decides what to do with each
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Class Method Summary collapse
- .file_regexp(file_name) ⇒ Object
-
.prepare_files(file_name, retention_limit) ⇒ Object
return a set of collected files with correct processing decisions.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(file_name, retention_limit) ⇒ Set
constructor
A new instance of Set.
- #process ⇒ Object
Constructor Details
#initialize(file_name, retention_limit) ⇒ Set
Returns a new instance of Set.
10 11 12 13 14 |
# File 'lib/lazy_rotator/set.rb', line 10 def initialize(file_name, retention_limit) # reverse the prepared set so that rotated naming works correctly # if I rename '1' to '2' and then '2' to '3', etc. I lose those files @files = self.class.prepare_files(file_name, retention_limit).reverse end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
8 9 10 |
# File 'lib/lazy_rotator/set.rb', line 8 def files @files end |
Class Method Details
.file_regexp(file_name) ⇒ Object
25 26 27 |
# File 'lib/lazy_rotator/set.rb', line 25 def file_regexp(file_name) Regexp.new("#{Regexp.quote(file_name)}(\\.\\d+)?$") end |
.prepare_files(file_name, retention_limit) ⇒ Object
return a set of collected files with correct processing decisions
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lazy_rotator/set.rb', line 30 def prepare_files(file_name, retention_limit) raw_files = collect_files(file_name.to_s) prepared_files = [File::Touch.new(file_name)] delete_after = retention_limit - 1 next_number = 1 raw_files.each do |file| prepared_files << prepare_file(file, delete_after, next_number) next_number += 1 end prepared_files end |
Instance Method Details
#each(&block) ⇒ Object
16 17 18 |
# File 'lib/lazy_rotator/set.rb', line 16 def each(&block) @files.each(&block) end |
#process ⇒ Object
20 21 22 |
# File 'lib/lazy_rotator/set.rb', line 20 def process map(&:process) end |