Class: Listen::Adapter::Base

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/listen/adapter/base.rb

Direct Known Subclasses

BSD, Darwin, Linux, Polling, TCP, Windows

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listener) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
# File 'lib/listen/adapter/base.rb', line 8

def initialize(listener)
  @listener = listener
rescue
  _log :error, "adapter config failed: #{$!}:#{$@.join("\n")}"
  raise
end

Instance Attribute Details

#listenerObject

Returns the value of attribute listener.



6
7
8
# File 'lib/listen/adapter/base.rb', line 6

def listener
  @listener
end

Class Method Details

.local_fs?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/listen/adapter/base.rb', line 27

def self.local_fs?
  true
end

.usable?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/listen/adapter/base.rb', line 31

def self.usable?
  const_get('OS_REGEXP') =~ RbConfig::CONFIG['target_os']
end

Instance Method Details

#_configureObject (private)



37
38
# File 'lib/listen/adapter/base.rb', line 37

def _configure
end

#_directoriesObject (private)



40
41
42
# File 'lib/listen/adapter/base.rb', line 40

def _directories
  listener.directories
end

#_log(type, message) ⇒ Object (private)



56
57
58
# File 'lib/listen/adapter/base.rb', line 56

def _log(type, message)
  Celluloid.logger.send(type, message)
end

#_notify_change(type, path, options = {}) ⇒ Object (private)



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/listen/adapter/base.rb', line 44

def _notify_change(type, path, options = {})
  unless (worker = listener.async(:change_pool))
    _log :warn, 'Failed to allocate worker from change pool'
    return
  end

  worker.change(type, path, options)
rescue RuntimeError
  _log :error, "_notify_change crashed: #{$!}:#{$@.join("\n")}"
  raise
end

#startObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/listen/adapter/base.rb', line 15

def start
  _configure
  Thread.new do
    begin
      _run
    rescue
      _log :error, "run() in thread failed: #{$!}:#{$@.join("\n")}"
      raise
    end
  end
end