Class: Listen::Forwarder

Inherits:
Object
  • Object
show all
Defined in:
lib/listen/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Forwarder

Returns a new instance of Forwarder.



36
37
38
# File 'lib/listen/cli.rb', line 36

def initialize(options)
  @options = options
end

Instance Method Details

#startObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/listen/cli.rb', line 40

def start
  puts "Starting listen..."
  address = @options[:forward]
  directory = @options[:directory]
  callback = Proc.new do |modified, added, removed|
    if @options[:verbose]
      puts "+ #{added}" unless added.empty?
      puts "- #{removed}" unless removed.empty?
      puts "> #{modified}" unless modified.empty?
    end
  end

  listener = Listen.to directory, forward_to: address, &callback
  listener.start

  while listener.listen?
    sleep 0.5
  end
end