class DAF::FileUpdateMonitor

Monitor that watches a file's last update time, and triggers when it changes includes several return outputs that can be used as well

Public Class Methods

new(options) click to toggle source
Calls superclass method DAF::Monitor::new
# File lib/daf/monitors/file_update_monitor.rb, line 21
def initialize(options)
  super
end

Public Instance Methods

block_until_triggered() click to toggle source
# File lib/daf/monitors/file_update_monitor.rb, line 25
def block_until_triggered
  initial_modified_time = File.mtime(@path.value)
  loop do
    sleep @frequency.value
    modified_time = File.mtime(@path.value)
    next unless modified_time > initial_modified_time
    @time = modified_time
    @contents = contents_of_file(@path.value)
    break
  end
end

Private Instance Methods

contents_of_file(path) click to toggle source
# File lib/daf/monitors/file_update_monitor.rb, line 37
def contents_of_file(path)
  file = File.open(path)
  contents = file.read
  file.close
  contents
end