Class: StorageGuardian::ColdDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/storage_guardian/cold_detector.rb

Instance Method Summary collapse

Constructor Details

#initialize(entries, threshold_days) ⇒ ColdDetector

Returns a new instance of ColdDetector.



5
6
7
8
9
# File 'lib/storage_guardian/cold_detector.rb', line 5

def initialize(entries, threshold_days)
  @entries         = entries
  @threshold_days  = threshold_days
  @cutoff          = Time.now - (threshold_days * 86400)
end

Instance Method Details

#detectObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/storage_guardian/cold_detector.rb', line 11

def detect
  @entries.select { |e| e.mtime < @cutoff }.map do |e|
    {
      type:          :cold_file,
      severity:      :low,
      path:          e.path,
      size_mb:       (e.size / 1024.0 / 1024.0).round(2),
      last_modified: e.mtime,
      days_old:      ((Time.now - e.mtime) / 86400).round,
      message:       "File #{e.path} not modified for #{((Time.now - e.mtime) / 86400).round} days (#{(e.size / 1024.0 / 1024.0).round(2)}MB)"
    }
  end
end