Module: Listen

Defined in:
lib/listen/adapter/bsd.rb,
lib/listen.rb,
lib/listen/cli.rb,
lib/listen/file.rb,
lib/listen/change.rb,
lib/listen/record.rb,
lib/listen/adapter.rb,
lib/listen/options.rb,
lib/listen/version.rb,
lib/listen/listener.rb,
lib/listen/silencer.rb,
lib/listen/directory.rb,
lib/listen/adapter/tcp.rb,
lib/listen/tcp/message.rb,
lib/listen/adapter/base.rb,
lib/listen/record/entry.rb,
lib/listen/adapter/linux.rb,
lib/listen/adapter/darwin.rb,
lib/listen/adapter/polling.rb,
lib/listen/adapter/windows.rb,
lib/listen/queue_optimizer.rb,
lib/listen/tcp/broadcaster.rb,
lib/listen/internals/logging.rb,
lib/listen/internals/thread_pool.rb,
lib/listen/record/symlink_detector.rb

Overview

Listener implementation for BSD's kqueue.

Defined Under Namespace

Modules: Adapter, Internals, QueueOptimizer, TCP Classes: CLI, Change, Directory, File, Forwarder, Listener, Options, Record, Silencer

Constant Summary collapse

VERSION =
'2.8.0'

Class Method Summary collapse

Class Method Details

._add_listener(*args, &block) ⇒ Object (private)



69
70
71
72
73
74
# File 'lib/listen.rb', line 69

def _add_listener(*args, &block)
  @listeners ||= []
  Listener.new(*args, &block).tap do |listener|
    @listeners << listener
  end
end

.on(target, *args) {|modified, added, removed| ... } ⇒ Listen::Listener

Listens to file system modifications broadcast over TCP.

Parameters:

  • target (String/Fixnum)

    to listen on (hostname:port or port)

Yields:

  • (modified, added, removed)

    the changed files

Yield Parameters:

  • modified (Array<String>)

    the list of modified files

  • added (Array<String>)

    the list of added files

  • removed (Array<String>)

    the list of removed files

Returns:



63
64
65
# File 'lib/listen.rb', line 63

def on(target, *args, &block)
  _add_listener(target, :recipient, *args, &block)
end

.stopObject

Stop all listeners & Celluloid

Use it for testing purpose or when you are sure that Celluloid could be ended.

This is used by the listen binary to handle Ctrl-C



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/listen.rb', line 38

def stop
  Internals::ThreadPool.stop
  @listeners ||= []

  # TODO: should use a mutex for this
  @listeners.each do |listener|
    # call stop to halt the main loop
    listener.stop
  end
  @listeners = nil

  Celluloid.shutdown
end

.to(*args) {|modified, added, removed| ... } ⇒ Listen::Listener

Listens to file system modifications on a either single directory or multiple directories.

When :forward_to is specified, this listener will broadcast modifications over TCP.

Yields:

  • (modified, added, removed)

    the changed files

Yield Parameters:

  • modified (Array<String>)

    the list of modified files

  • added (Array<String>)

    the list of added files

  • removed (Array<String>)

    the list of removed files

Returns:



23
24
25
26
27
28
29
# File 'lib/listen.rb', line 23

def to(*args, &block)
  Celluloid.boot unless Celluloid.running?
  options = args.last.is_a?(Hash) ? args.last : {}
  target = options.delete(:forward_to)
  args = ([target, :broadcaster] + args) if target
  _add_listener(*args, &block)
end