Class: Dirwatch::Settings::WatchSetting
- Defined in:
- lib/dirwatch/settings/watch_setting.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#file_match ⇒ Object
readonly
Returns the value of attribute file_match.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#scripts ⇒ Object
readonly
Returns the value of attribute scripts.
Instance Method Summary collapse
- #exec_scripts ⇒ Object
- #files ⇒ Object
- #files_path ⇒ Object
-
#initialize(directory:, file_match:, interval:, scripts:) ⇒ WatchSetting
constructor
A new instance of WatchSetting.
- #to_s ⇒ Object
Constructor Details
#initialize(directory:, file_match:, interval:, scripts:) ⇒ WatchSetting
8 9 10 11 12 13 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 8 def initialize directory:, file_match:, interval:, scripts: self.directory = directory self.file_match = file_match self.interval = interval self.scripts = scripts end |
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
6 7 8 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 6 def directory @directory end |
#file_match ⇒ Object
Returns the value of attribute file_match.
6 7 8 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 6 def file_match @file_match end |
#interval ⇒ Object
Returns the value of attribute interval.
6 7 8 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 6 def interval @interval end |
#scripts ⇒ Object
Returns the value of attribute scripts.
6 7 8 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 6 def scripts @scripts end |
Instance Method Details
#exec_scripts ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 23 def exec_scripts @scripts.each do |script| if script =~ / & *\z/ system script else output = `#{script}` unless $CHILD_STATUS.successful? raise "The command \"#{script}\" failed with: #{output}" end end end end |
#files ⇒ Object
19 20 21 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 19 def files Dir[files_path] end |
#files_path ⇒ Object
15 16 17 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 15 def files_path File.join @directory, '**', @file_match end |
#to_s ⇒ Object
36 37 38 39 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 36 def to_s variables = [:files_path, :interval, :scripts].map {|v| "#{v}=#{send(v).inspect}" } "#<#{self.class} #{variables.join ' '}>" end |