Class: God::Conditions::FileTouched

Inherits:
PollCondition show all
Defined in:
lib/god/conditions/file_touched.rb

Overview

Condition Symbol :file_touched Type: Poll

Trigger when a specified file is touched.

Paramaters

Required
  +path+ is the path to the file to watch.

Examples

Trigger if ‘tmp/restart.txt’ file is touched (from a Watch):

on.condition(:file_touched) do |c|
  c.path = 'tmp/restart.txt'
end

Instance Attribute Summary collapse

Attributes inherited from PollCondition

#interval

Attributes inherited from God::Condition

#info, #notify, #phase, #transition

Attributes inherited from Behavior

#watch

Instance Method Summary collapse

Methods inherited from PollCondition

#after, #before

Methods inherited from God::Condition

#friendly_name, generate, valid?

Methods inherited from Behavior

#after_restart, #after_start, #after_stop, #before_restart, #before_start, #before_stop, #friendly_name, generate

Methods included from God::Configurable

#base_name, complain, #complain, #friendly_name, #prepare, #reset

Constructor Details

#initializeFileTouched

Returns a new instance of FileTouched.



24
25
26
27
# File 'lib/god/conditions/file_touched.rb', line 24

def initialize
  super
  self.path = nil
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



22
23
24
# File 'lib/god/conditions/file_touched.rb', line 22

def path
  @path
end

Instance Method Details

#testObject



35
36
37
38
39
40
41
# File 'lib/god/conditions/file_touched.rb', line 35

def test
  if File.exists?(self.path)
    (Time.now - File.mtime(self.path)) <= self.interval
  else
    false
  end
end

#valid?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/god/conditions/file_touched.rb', line 29

def valid?
  valid = true
  valid &= complain("Attribute 'path' must be specified", self) if self.path.nil?
  valid
end