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.
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
-
#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.
25 26 27 28 |
# File 'lib/god/conditions/file_touched.rb', line 25 def initialize super self.path = nil end |
Instance Attribute Details
#path ⇒ Object
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
#test ⇒ Object
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
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 |