Class: Stenohttp2::Common::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/stenohttp2/common/watcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Watcher

Returns a new instance of Watcher.



8
9
10
# File 'lib/stenohttp2/common/watcher.rb', line 8

def initialize(dir)
  @path = File.expand_path(dir)
end

Instance Method Details

#startObject



12
13
14
15
16
17
18
19
20
# File 'lib/stenohttp2/common/watcher.rb', line 12

def start
  puts "Listening on #{path} for *.message"
  listener = Listen.to(path) do |modified, added, _|
    new_file = added&.first || modified&.first
    decode_message(File.read(new_file)) if new_file&.end_with?('message')
  end
  listener.start
  sleep
end