Class: BackupMonitor::Checker

Inherits:
Object
  • Object
show all
Defined in:
lib/backup_monitor/checker.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Checker

Returns a new instance of Checker.



7
8
9
# File 'lib/backup_monitor/checker.rb', line 7

def initialize(options = {})
	@warning_threshold = options.delete(:warning_threshold)._? { raise ArgumentError, ':warning_threshold (seconds) must be supplied in options hash' }
end

Instance Method Details

#check(path) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/backup_monitor/checker.rb', line 11

def check(path)
	pathname = real_path path
	result = {}
	Dir[pathname.join('*')].each do |d|
		full_path = pathname.join d
		next if %w[. ..].include? d
		next unless File.directory? full_path
		dir_mtime = DirectoryHierarchyModificationTime.modification_time full_path
		if dir_mtime.nil?
			# No files in the tree
			result[full_path] = Time.at(0)
		else
			result[full_path] = dir_mtime if (Time.now - dir_mtime).to_i > @warning_threshold
		end
	end
	result
end

#real_path(path) ⇒ Object

This method wrapper exists solely for testing due to some outstanding bugs in FakeFS



31
32
33
# File 'lib/backup_monitor/checker.rb', line 31

def real_path(path)
	Pathname.new(path).realpath
end