Class: Listen::Listener
- Inherits:
-
Object
- Object
- Listen::Listener
- Includes:
- Celluloid::FSM, Internals::Logging, QueueOptimizer
- Defined in:
- lib/listen/listener.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#directories ⇒ Object
readonly
TODO: deprecate.
-
#host ⇒ Object
readonly
TODO: deprecate NOTE: these are VERY confusing (broadcast + recipient modes).
-
#options ⇒ Object
readonly
TODO: deprecate.
-
#port ⇒ Object
readonly
TODO: deprecate NOTE: these are VERY confusing (broadcast + recipient modes).
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
-
#silencer ⇒ Object
readonly
Returns the value of attribute silencer.
-
#supervisor ⇒ Object
readonly
Returns the value of attribute supervisor.
Instance Method Summary collapse
- #async(type) ⇒ Object
-
#ignore(regexps) ⇒ Object
Add files and dirs to ignore on top of defaults.
-
#ignore!(regexps) ⇒ Object
Replace default ignore patterns with provided regexp.
-
#initialize(*args) {|modified, added, removed| ... } ⇒ Listener
constructor
Initializes the directories listener.
-
#only(regexps) ⇒ Object
Listen only to files and dirs matching regexp.
-
#pause ⇒ Object
Stops invoking callbacks (messages pile up).
-
#paused=(value) ⇒ Object
TODO: deprecate.
- #paused? ⇒ Boolean (also: #paused)
-
#processing? ⇒ Boolean
(also: #listen?)
processing means callbacks are called.
- #queue(type, change, dir, path, options = {}) ⇒ Object
-
#start ⇒ Object
(also: #unpause)
Starts processing events and starts adapters or resumes invoking callbacks if paused.
-
#stop ⇒ Object
Stops processing and terminates all actors.
- #sync(type) ⇒ Object
Methods included from Internals::Logging
#_debug, #_error_exception, #_format_error, #_info, #_log, #_warn
Constructor Details
#initialize(*args) {|modified, added, removed| ... } ⇒ Listener
Initializes the directories listener.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/listen/listener.rb', line 40 def initialize(*args, &block) @options = (args.last.is_a?(Hash) ? args.pop : {}) # Setup logging first if Celluloid.logger Celluloid.logger.level = _debug_level _info "Celluloid loglevel set to: #{Celluloid.logger.level}" _info "Listen version: #{Listen::VERSION}" end @silencer = Silencer.new _reconfigure_silencer({}) @tcp_mode = nil if [:recipient, :broadcaster].include? args[1] target = args.shift @tcp_mode = args.shift (target) end @directories = args.flatten.map { |path| Pathname.new(path).realpath } @queue = Queue.new @block = block @registry = Celluloid::Registry.new transition :stopped end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
18 19 20 |
# File 'lib/listen/listener.rb', line 18 def block @block end |
#directories ⇒ Object (readonly)
TODO: deprecate
23 24 25 |
# File 'lib/listen/listener.rb', line 23 def directories @directories end |
#host ⇒ Object (readonly)
TODO: deprecate NOTE: these are VERY confusing (broadcast + recipient modes)
28 29 30 |
# File 'lib/listen/listener.rb', line 28 def host @host end |
#options ⇒ Object (readonly)
TODO: deprecate
23 24 25 |
# File 'lib/listen/listener.rb', line 23 def @options end |
#port ⇒ Object (readonly)
TODO: deprecate NOTE: these are VERY confusing (broadcast + recipient modes)
28 29 30 |
# File 'lib/listen/listener.rb', line 28 def port @port end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
24 25 26 |
# File 'lib/listen/listener.rb', line 24 def registry @registry end |
#silencer ⇒ Object (readonly)
Returns the value of attribute silencer.
20 21 22 |
# File 'lib/listen/listener.rb', line 20 def silencer @silencer end |
#supervisor ⇒ Object (readonly)
Returns the value of attribute supervisor.
24 25 26 |
# File 'lib/listen/listener.rb', line 24 def supervisor @supervisor end |
Instance Method Details
#async(type) ⇒ Object
154 155 156 157 |
# File 'lib/listen/listener.rb', line 154 def async(type) proxy = sync(type) proxy ? proxy.async : nil end |
#ignore(regexps) ⇒ Object
Add files and dirs to ignore on top of defaults
(@see Listen::Silencer for default ignored files and dirs)
140 141 142 |
# File 'lib/listen/listener.rb', line 140 def ignore(regexps) _reconfigure_silencer(ignore: [[:ignore], regexps]) end |
#ignore!(regexps) ⇒ Object
Replace default ignore patterns with provided regexp
145 146 147 |
# File 'lib/listen/listener.rb', line 145 def ignore!(regexps) _reconfigure_silencer(ignore: [], ignore!: regexps) end |
#only(regexps) ⇒ Object
Listen only to files and dirs matching regexp
150 151 152 |
# File 'lib/listen/listener.rb', line 150 def only(regexps) _reconfigure_silencer(only: regexps) end |
#pause ⇒ Object
Stops invoking callbacks (messages pile up)
112 113 114 |
# File 'lib/listen/listener.rb', line 112 def pause transition :paused end |
#paused=(value) ⇒ Object
TODO: deprecate
129 130 131 |
# File 'lib/listen/listener.rb', line 129 def paused=(value) transition value ? :paused : :processing end |
#paused? ⇒ Boolean Also known as: paused
121 122 123 |
# File 'lib/listen/listener.rb', line 121 def paused? state == :paused end |
#processing? ⇒ Boolean Also known as: listen?
processing means callbacks are called
117 118 119 |
# File 'lib/listen/listener.rb', line 117 def processing? state == :processing end |
#queue(type, change, dir, path, options = {}) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/listen/listener.rb', line 163 def queue(type, change, dir, path, = {}) 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) if @options[:relative] dir = begin cwd = Pathname.pwd dir.relative_path_from(cwd) rescue ArgumentError dir end end @queue << [type, change, dir, path, ] @last_queue_event_time = Time.now.to_f _wakeup_wait_thread unless state == :paused return unless @tcp_mode == :broadcaster = TCP::Message.new(type, change, dir, path, ) registry[:broadcaster].async.broadcast(.payload) end |
#start ⇒ Object Also known as: unpause
Starts processing events and starts adapters or resumes invoking callbacks if paused
99 100 101 |
# File 'lib/listen/listener.rb', line 99 def start transition :processing end |
#stop ⇒ Object
Stops processing and terminates all actors
107 108 109 |
# File 'lib/listen/listener.rb', line 107 def stop transition :stopped end |
#sync(type) ⇒ Object
159 160 161 |
# File 'lib/listen/listener.rb', line 159 def sync(type) @registry[type] end |