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.

Parameters

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.



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

def initialize
  super
  self.path = nil
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#testObject



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

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

#valid?Boolean

Returns:

  • (Boolean)


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

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