Skip to content

Instantly share code, notes, and snippets.

@bantic
Created June 17, 2010 22:34
Show Gist options
  • Save bantic/442896 to your computer and use it in GitHub Desktop.
Save bantic/442896 to your computer and use it in GitHub Desktop.
module God
module Conditions
class FileTouched < PollCondition
attr_accessor :path
def initialize
super
self.path = nil
end
def valid?
valid = true
valid &= complain("Attribute 'path' must be specified", self) if self.path.nil?
valid
end
def touch_file
FileUtils.touch(self.path)
FileUtils.chown(self.watch.uid, self.watch.gid, self.path)
end
def test
touch_file unless File.exists?(self.path)
@mtime ||= File.mtime(self.path)
if @mtime != File.mtime(self.path)
@mtime = nil
true
else
false
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment