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.
13 14 15 16 |
# File 'lib/avm/data/rotate.rb', line 13 def initialize(source_path, = {}) @source_path = source_path @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/avm/data/rotate.rb', line 11 def @options end |
#source_path ⇒ Object (readonly)
Returns the value of attribute source_path.
11 12 13 |
# File 'lib/avm/data/rotate.rb', line 11 def source_path @source_path end |
Instance Method Details
#oldest_rotated_file ⇒ Object
42 43 44 |
# File 'lib/avm/data/rotate.rb', line 42 def oldest_rotated_file rotated_files.min_by { |file| [::File.mtime(file)] } end |
#rotated_files ⇒ Object
38 39 40 |
# File 'lib/avm/data/rotate.rb', line 38 def rotated_files ::Dir["#{dirname}/#{source_basename_without_extension}*#{source_extension}"] end |
#run ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/avm/data/rotate.rb', line 18 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
27 28 29 30 31 32 |
# File 'lib/avm/data/rotate.rb', line 27 def space_limit r = [:space_limit].try(:to_i) return r if r.present? && r.positive? r end |
#space_used ⇒ Object
34 35 36 |
# File 'lib/avm/data/rotate.rb', line 34 def space_used rotated_files.inject(0) { |a, e| a + ::File.size(e) } end |