Class: Spring::Watcher::Listen
Instance Attribute Summary collapse
Attributes inherited from Abstract
#directories, #files, #latency, #root
Instance Method Summary
collapse
Methods inherited from Abstract
#add, #initialize, #mark_stale, #on_stale, #restart, #stale?
Instance Attribute Details
#listener ⇒ Object
Returns the value of attribute listener.
8
9
10
|
# File 'lib/spring/watcher/listen.rb', line 8
def listener
@listener
end
|
Instance Method Details
#base_directories ⇒ Object
44
45
46
47
48
49
|
# File 'lib/spring/watcher/listen.rb', line 44
def base_directories
([root] +
files.reject { |f| f.start_with? root }.map { |f| File.expand_path("#{f}/..") } +
directories.reject { |d| d.start_with? root }
).uniq
end
|
#changed(modified, added, removed) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/spring/watcher/listen.rb', line 36
def changed(modified, added, removed)
synchronize do
if (modified + added + removed).any? { |f| watching? f }
mark_stale
end
end
end
|
#start ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'lib/spring/watcher/listen.rb', line 10
def start
unless @listener
@listener = ::Listen.to(*base_directories, relative_paths: false)
@listener.latency(latency)
@listener.change(&method(:changed))
@listener.start
end
end
|
#stop ⇒ Object
19
20
21
22
23
24
|
# File 'lib/spring/watcher/listen.rb', line 19
def stop
if @listener
@listener.stop
@listener = nil
end
end
|
#subjects_changed ⇒ Object
26
27
28
29
30
|
# File 'lib/spring/watcher/listen.rb', line 26
def subjects_changed
if @listener && @listener.directories.sort != base_directories.sort
restart
end
end
|
#watching?(file) ⇒ Boolean
32
33
34
|
# File 'lib/spring/watcher/listen.rb', line 32
def watching?(file)
files.include?(file) || file.start_with?(*directories)
end
|