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
# File lib/listen/listener.rb, line 144 def async(type) proxy = sync(type) proxy ? proxy.async : nil end
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
Replace default ignore patterns with provided regexp
# File lib/listen/listener.rb, line 135 def ignore!(regexps) _reconfigure_silencer(ignore: [], ignore!: regexps) end
Listen only to files and dirs matching regexp
# File lib/listen/listener.rb, line 140 def only(regexps) _reconfigure_silencer(only: regexps) end
Stops invoking callbacks (messages pile up)
# File lib/listen/listener.rb, line 102 def pause transition :paused end
TODO: deprecate
# File lib/listen/listener.rb, line 119 def paused=(value) transition value ? :paused : :processing end
# File lib/listen/listener.rb, line 111 def paused? state == :paused end
processing means callbacks are called
# File lib/listen/listener.rb, line 107 def processing? state == :processing end
# 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
Starts processing events and starts adapters or resumes invoking callbacks if paused
# File lib/listen/listener.rb, line 89 def start transition :processing end
Stops processing and terminates all actors
# File lib/listen/listener.rb, line 97 def stop transition :stopped end
Generated with the Darkfish Rdoc Generator 2.