Parent

Included Modules

Listen::Listener

Attributes

block[RW]
directories[R]

TODO: deprecate

host[R]
options[R]

TODO: deprecate

port[R]
registry[R]
silencer[R]
supervisor[R]

Public Class Methods

new(*args, &block) click to toggle source

Initializes the directories listener.

@param [String] directory the directories to listen to @param [Hash] options the listen options (see Listen::Listener::Options)

@yield [modified, added, removed] the changed files @yieldparam [Array<String>] modified the list of modified files @yieldparam [Array<String>] added the list of added files @yieldparam [Array<String>] removed the list of removed files

# File lib/listen/listener.rb, line 33
def initialize(*args, &block)
  @options = _init_options(args.last.is_a?(Hash) ? args.pop : {})

  # Setup logging first
  Celluloid.logger.level = _debug_level
  _log :info, "Celluloid loglevel set to: #{Celluloid.logger.level}"

  @silencer = Silencer.new
  _reconfigure_silencer({})

  @tcp_mode = nil
  if [:recipient, :broadcaster].include? args[1]
    target = args.shift
    @tcp_mode = args.shift
    _init_tcp_options(target)
  end

  @directories = args.flatten.map { |path| Pathname.new(path).realpath }
  @queue = Queue.new
  @block = block
  @registry = Celluloid::Registry.new

  transition :stopped
end

Public Instance Methods

async(type) click to toggle source
# File lib/listen/listener.rb, line 144
def async(type)
  proxy = sync(type)
  proxy ? proxy.async : nil
end
ignore(regexps) click to toggle source

Add files and dirs to ignore on top of defaults

(@see Listen::Silencer for default ignored files and dirs)

# File lib/listen/listener.rb, line 130
def ignore(regexps)
  _reconfigure_silencer(ignore: [options[:ignore], regexps])
end
ignore!(regexps) click to toggle source

Replace default ignore patterns with provided regexp

# File lib/listen/listener.rb, line 135
def ignore!(regexps)
  _reconfigure_silencer(ignore: [], ignore!: regexps)
end
listen?() click to toggle source

TODO: deprecate

Alias for: processing?
only(regexps) click to toggle source

Listen only to files and dirs matching regexp

# File lib/listen/listener.rb, line 140
def only(regexps)
  _reconfigure_silencer(only: regexps)
end
pause() click to toggle source

Stops invoking callbacks (messages pile up)

# File lib/listen/listener.rb, line 102
def pause
  transition :paused
end
paused() click to toggle source

TODO: deprecate

Alias for: paused?
paused=(value) click to toggle source

TODO: deprecate

# File lib/listen/listener.rb, line 119
def paused=(value)
  transition value ? :paused : :processing
end
paused?() click to toggle source
# File lib/listen/listener.rb, line 111
def paused?
  state == :paused
end
Also aliased as: paused
processing?() click to toggle source

processing means callbacks are called

# File lib/listen/listener.rb, line 107
def processing?
  state == :processing
end
Also aliased as: listen?
queue(type, change, dir, path, options = {}) click to toggle source
# File lib/listen/listener.rb, line 153
def queue(type, change, dir, path, options = {})
  fail "Invalid type: #{type.inspect}" unless [:dir, :file].include? type
  fail "Invalid change: #{change.inspect}" unless change.is_a?(Symbol)
  fail "Invalid path: #{path.inspect}" unless path.is_a?(String)
  @queue << [type, change, dir, path, options]

  @last_queue_event_time = Time.now.to_f
  _wakeup_wait_thread unless state == :paused

  return unless @tcp_mode == :broadcaster

  message = TCP::Message.new(type, change, dir, path, options)
  registry[:broadcaster].async.broadcast(message.payload)
end
start() click to toggle source

Starts processing events and starts adapters or resumes invoking callbacks if paused

# File lib/listen/listener.rb, line 89
def start
  transition :processing
end
Also aliased as: unpause
stop() click to toggle source

Stops processing and terminates all actors

# File lib/listen/listener.rb, line 97
def stop
  transition :stopped
end
sync(type) click to toggle source
# File lib/listen/listener.rb, line 149
def sync(type)
  @registry[type]
end
unpause() click to toggle source

TODO: depreciate

Alias for: start

[Validate]

Generated with the Darkfish Rdoc Generator 2.