Class: Avm::Data::Rotate
- Inherits:
-
Object
- Object
- Avm::Data::Rotate
- Includes:
- EacRubyUtils::SimpleCache
- Defined in:
- lib/avm/data/rotate.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#source_path ⇒ Object
readonly
Returns the value of attribute source_path.
Instance Method Summary collapse
-
#initialize(source_path, options = {}) ⇒ Rotate
constructor
A new instance of Rotate.
- #oldest_rotated_file ⇒ Object
- #rotated_files ⇒ Object
- #run ⇒ Object
- #space_limit ⇒ Object
- #space_used ⇒ Object
Constructor Details
#initialize(source_path, options = {}) ⇒ Rotate
Returns a new instance of Rotate.
12 13 14 15 |
# File 'lib/avm/data/rotate.rb', line 12 def initialize(source_path, = {}) @source_path = source_path @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/avm/data/rotate.rb', line 10 def @options end |
#source_path ⇒ Object (readonly)
Returns the value of attribute source_path.
10 11 12 |
# File 'lib/avm/data/rotate.rb', line 10 def source_path @source_path end |
Instance Method Details
#oldest_rotated_file ⇒ Object
41 42 43 |
# File 'lib/avm/data/rotate.rb', line 41 def oldest_rotated_file rotated_files.min_by { |file| [::File.mtime(file)] } end |
#rotated_files ⇒ Object
37 38 39 |
# File 'lib/avm/data/rotate.rb', line 37 def rotated_files ::Dir["#{dirname}/#{source_basename_without_extension}*#{source_extension}"] end |
#run ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/avm/data/rotate.rb', line 17 def run validate_msg = validate return validate_msg if validate_msg.present? ::FileUtils.mv(source_path, target_path) check_space_limit nil end |
#space_limit ⇒ Object
26 27 28 29 30 31 |
# File 'lib/avm/data/rotate.rb', line 26 def space_limit r = [:space_limit].try(:to_i) return r if r.present? && r.positive? r end |
#space_used ⇒ Object
33 34 35 |
# File 'lib/avm/data/rotate.rb', line 33 def space_used rotated_files.inject(0) { |a, e| a + ::File.size(e) } end |