class Sicily::Monitor
Public Instance Methods
on(path, &user_rule_block)
click to toggle source
# File lib/sicily/monitor.rb, line 10 def on(path, &user_rule_block) attach_monitor(path, &user_rule_block) consume_all(path, &user_rule_block) end
Private Instance Methods
already_existing_files(path)
click to toggle source
# File lib/sicily/monitor.rb, line 24 def already_existing_files(path) Dir["#{File.expand_path(path)}/**/*"] end
attach_monitor(path, &user_rule_block)
click to toggle source
# File lib/sicily/monitor.rb, line 28 def attach_monitor(path, &user_rule_block) Sicily.logger.info "Starting a monitor on #{path}" path = validate_and_expand_path(path) start_listener(path) do |files| BatchProcessor.new(files).run(&user_rule_block) end end
consume_all(path, &user_rule_block)
click to toggle source
# File lib/sicily/monitor.rb, line 17 def consume_all(path, &user_rule_block) return unless Sicily.config.consume_on_start files = already_existing_files(path) BatchProcessor.new(files).run(&user_rule_block) end
start_listener(path) { |added| ... }
click to toggle source
# File lib/sicily/monitor.rb, line 42 def start_listener(path) delay = Sicily.config.delay_on_file_monitoring listener = Listen.to(path, wait_for_delay: delay) do |_modified, added, _removed| yield added end listener.start end
validate_and_expand_path(path)
click to toggle source
# File lib/sicily/monitor.rb, line 36 def validate_and_expand_path(path) path = File.expand_path(path) raise MonitorError, "Monitor Failed. Unknown path : #{path}" unless File.exist?(path) path end