Module: WatchConfig::ClassMethods

Defined in:
lib/file_watcher/watch_config.rb

Instance Method Summary collapse

Instance Method Details

#new_watch_job {|wj| ... } ⇒ Object

Yields:

  • (wj)


21
22
23
24
25
26
27
28
# File 'lib/file_watcher/watch_config.rb', line 21

def new_watch_job &block
  wj = self.new 

  yield wj

  validate_new_job wj 
  self.registered_jobs << wj
end

#validate_new_job(wj) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/file_watcher/watch_config.rb', line 8

def validate_new_job wj
  raise "Error: Watch job is missing watch dir: #{wj.inspect}" unless wj.watch_criteria.keys.include? :target_dir

  raise "Error: Watch directory doesn't exist: #{wj.watch_criteria[:target_dir]}" unless File.exist? wj.watch_criteria[:target_dir]

  raise "Error: Watch configuration did not specify any events to watch for (#{wj.inspect})" if wj.watch_criteria[:events].empty?


  raise "Error: Only http watch actions are supported: #{wj}" unless wj.watch_action.keys == [:http]

  raise "Error: Invalid/Unsupported http method [#{wj.watch_action[:http][:method]}] in config [#{wj.watch_action.inspect}]" unless wj.watch_action[:http][:method] == :post
end