Parent

Listen::Listener

Attributes

block[RW]
changes[RW]
directories[RW]
options[RW]
paused[RW]
thread[RW]

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 23
def initialize(*args, &block)
  @options     = _init_options(args.last.is_a?(Hash) ? args.pop : {})
  @directories = args.flatten.map { |path| Pathname.new(path).realpath }
  @changes     = []
  @block       = block
  _init_debug
end

Public Instance Methods

ignore(regexps) click to toggle source

Adds ignore patterns to the existing one (See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer)

@param [Regexp, Hash<Regexp>] new ignoring patterns.

# File lib/listen/listener.rb, line 86
def ignore(regexps)
  options[:ignore] = [options[:ignore], regexps]
  Celluloid::Actor[:listen_silencer] = Silencer.new(options)
end
ignore!(regexps) click to toggle source

Overwrites ignore patterns (See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer)

@param [Regexp, Hash<Regexp>] new ignoring patterns.

# File lib/listen/listener.rb, line 95
def ignore!(regexps)
  options.delete(:ignore)
  options[:ignore!] = regexps
  Celluloid::Actor[:listen_silencer] = Silencer.new(options)
end
listen?() click to toggle source

Returns true if Listener is not paused

@return [Boolean]

# File lib/listen/listener.rb, line 78
def listen?
  @paused == false
end
pause() click to toggle source

Pauses listening callback (adapter still running)

# File lib/listen/listener.rb, line 55
def pause
  @paused = true
end
paused?() click to toggle source

Returns true if Listener is paused

@return [Boolean]

# File lib/listen/listener.rb, line 70
def paused?
  @paused == true
end
start() click to toggle source

Starts the listener by initializing the adapter and building the directory record concurrently, then it starts the adapter to watch for changes. The current thread is not blocked after starting.

# File lib/listen/listener.rb, line 35
def start
  _signals_trap
  _init_actors
  unpause
  Celluloid::Actor[:listen_adapter].async.start
  @thread = Thread.new { _wait_for_changes }
end
stop() click to toggle source

Terminates all Listen actors and kill the adapter.

# File lib/listen/listener.rb, line 45
def stop
  thread.kill
  Celluloid::Actor.kill(Celluloid::Actor[:listen_adapter])
  Celluloid::Actor[:listen_silencer].terminate
  Celluloid::Actor[:listen_change_pool].terminate
  Celluloid::Actor[:listen_record].terminate
end
unpause() click to toggle source

Unpauses listening callback

# File lib/listen/listener.rb, line 61
def unpause
  Celluloid::Actor[:listen_record].build
  @paused = false
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.