Class: Listen::Adapter::Base
- Inherits:
-
Object
- Object
- Listen::Adapter::Base
show all
- Includes:
- Celluloid
- Defined in:
- lib/listen/adapter/base.rb
Constant Summary
collapse
- DEFAULTS =
{}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts) ⇒ Base
Returns a new instance of Base.
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/listen/adapter/base.rb', line 13
def initialize(opts)
@configured = nil
options = opts.dup
@mq = options.delete(:mq)
@directories = options.delete(:directories)
Array(@directories).each do |dir|
next if dir.is_a?(Pathname)
fail ArgumentError, "not a Pathname: #{dir.inspect}"
end
@recursion = options.delete(:recursion)
@recursion = true if @recursion.nil?
defaults = self.class.const_get('DEFAULTS')
@options = Listen::Options.new(options, defaults)
rescue
_log :error, "adapter config failed: #{$!}:#{$@.join("\n")}"
raise
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
8
9
10
|
# File 'lib/listen/adapter/base.rb', line 8
def options
@options
end
|
Class Method Details
._log(*args) ⇒ Object
86
87
88
|
# File 'lib/listen/adapter/base.rb', line 86
def self._log(*args)
Celluloid.logger.send(*args)
end
|
.local_fs? ⇒ Boolean
66
67
68
|
# File 'lib/listen/adapter/base.rb', line 66
def self.local_fs?
true
end
|
.usable? ⇒ Boolean
70
71
72
|
# File 'lib/listen/adapter/base.rb', line 70
def self.usable?
const_get('OS_REGEXP') =~ RbConfig::CONFIG['target_os']
end
|
Instance Method Details
#_log(*args) ⇒ Object
82
83
84
|
# File 'lib/listen/adapter/base.rb', line 82
def _log(*args)
self.class.send(:_log, *args)
end
|
#_queue_change(type, dir, rel_path, options) ⇒ Object
76
77
78
79
80
|
# File 'lib/listen/adapter/base.rb', line 76
def _queue_change(type, dir, rel_path, options)
@mq.send(:_queue_raw_change, type, dir, rel_path, options)
end
|
TODO: it's a separate method as a temporary workaround for tests
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/listen/adapter/base.rb', line 36
def configure
return if @configured
@configured = true
@callbacks ||= {}
@directories.each do |dir|
unless dir.is_a?(Pathname)
fail ArgumentError, "not a Pathname: #{dir.inspect}"
end
callback = @callbacks[dir] || lambda do |event|
_process_event(dir, event)
end
@callbacks[dir] = callback
_configure(dir, &callback)
end
end
|
#start ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/listen/adapter/base.rb', line 54
def start
configure
Thread.new do
begin
_run
rescue
_log :error, "run() in thread failed: #{$!}:#{$@.join("\n")}"
raise
end
end
end
|