-
Notifications
You must be signed in to change notification settings - Fork 28
/
fssm.rb
74 lines (58 loc) · 2.05 KB
/
fssm.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
67
68
69
70
71
72
73
74
dir = File.expand_path(File.dirname(__FILE__))
$LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
require 'thread'
module FSSM
FSSMError = Class.new(StandardError)
FileNotFoundError = Class.new(FSSMError)
FileNotRealError = Class.new(FSSMError)
CallbackError = Class.new(FSSMError)
autoload :VERSION, 'fssm/version'
autoload :Pathname, 'fssm/pathname'
autoload :Support, 'fssm/support'
autoload :Tree, 'fssm/tree'
autoload :Path, 'fssm/path'
autoload :Monitor, 'fssm/monitor'
module State
autoload :Directory, 'fssm/state/directory'
autoload :File, 'fssm/state/file'
end
module Backends
autoload :Polling, 'fssm/backends/polling'
autoload :FSEvents, 'fssm/backends/fsevents'
autoload :RBFSEvent, 'fssm/backends/rbfsevent'
autoload :Inotify, 'fssm/backends/inotify'
class << self
def set_backend(const_symbol=nil, value=nil)
const_symbol ||= :Default
value ||= ::FSSM::Support.backend
if (value.is_a?(Symbol) || value.is_a?(String))
unless const_defined?(value)
raise NameError,
"uninitialized constant FSSM::Backends::#{value}"
end
value = const_get(value)
end
unless value.is_a?(Class)
raise ArgumentError,
"value must be a class or the symbol of an existing backend"
end
remove_const(const_symbol) if const_defined?(const_symbol)
const_set(const_symbol, value)
end
def const_missing(symbol)
symbol == :Default ? set_backend(symbol, FSSM::Support.backend) : super
end
end
end
class << self
def dbg(msg=nil)
STDERR.puts("FSSM -> #{msg}")
end
def monitor(*args, &block)
options = args[-1].is_a?(Hash) ? args.pop : {}
monitor = FSSM::Monitor.new(options)
FSSM::Support.use_block(args.empty? ? monitor : monitor.path(*args), block)
monitor.run
end
end
end