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.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#scripts ⇒ Object
readonly
Returns the value of attribute scripts.
Instance Method Summary collapse
- #exec_scripts(verbose) ⇒ Object
- #files ⇒ Object
- #files_path ⇒ Object
-
#initialize(key, directory:, file_match:, interval:, scripts:) ⇒ WatchSetting
constructor
A new instance of WatchSetting.
- #inspect ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(key, directory:, file_match:, interval:, scripts:) ⇒ WatchSetting
Returns a new instance of WatchSetting.
8 9 10 11 12 13 14 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 8 def initialize key, directory:, file_match:, interval:, scripts: self.key = key 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 |
#key ⇒ Object
Returns the value of attribute key.
6 7 8 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 6 def key @key 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(verbose) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 24 def exec_scripts verbose @scripts.each do |script| if script =~ / & *\z/ puts " Call #{script.inspect} in background" if verbose system script else puts " Call #{script.inspect} in foreground" if verbose output = `#{script}` unless $CHILD_STATUS.success? raise "The command \"#{script}\" failed with: #{output}" end end end end |
#files ⇒ Object
20 21 22 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 20 def files Dir[files_path] end |
#files_path ⇒ Object
16 17 18 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 16 def files_path File.join @directory, '**', @file_match end |
#inspect ⇒ Object
48 49 50 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 48 def inspect "#<#{self.class} #{key}: #{to_s}>" end |
#to_h ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 39 def to_h { directory: directory, file_match: file_match, interval: interval, scripts: scripts, } end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/dirwatch/settings/watch_setting.rb', line 52 def to_s to_h.map {|k, v| "#{k}=#{v.inspect}" }.join ' ' end |