Class: Avm::Data::Rotate

Inherits:
Object
  • Object
show all
Includes:
EacRubyUtils::SimpleCache
Defined in:
lib/avm/data/rotate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @source_path = source_path
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/avm/data/rotate.rb', line 11

def options
  @options
end

#source_pathObject (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_fileObject



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_filesObject



38
39
40
# File 'lib/avm/data/rotate.rb', line 38

def rotated_files
  ::Dir["#{dirname}/#{source_basename_without_extension}*#{source_extension}"]
end

#runObject



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_limitObject



27
28
29
30
31
32
# File 'lib/avm/data/rotate.rb', line 27

def space_limit
  r = options[:space_limit].try(:to_i)
  return r if r.present? && r.positive?

  r
end

#space_usedObject



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