Class: God::Conditions::FileTouched
- Inherits:
-
PollCondition
- Object
- Behavior
- God::Condition
- PollCondition
- God::Conditions::FileTouched
- 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
-
#path ⇒ Object
Returns the value of attribute path.
Attributes inherited from PollCondition
Attributes inherited from God::Condition
#info, #notify, #phase, #transition
Attributes inherited from Behavior
Instance Method Summary collapse
-
#initialize ⇒ FileTouched
constructor
A new instance of FileTouched.
- #test ⇒ Object
- #valid? ⇒ Boolean
Methods inherited from PollCondition
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
#initialize ⇒ FileTouched
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
#path ⇒ Object
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
#test ⇒ Object
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
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 |