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
module Noah
class Watcher < Model
include WatcherValidations
attribute :pattern
attribute :endpoint
attribute :name
index :pattern
index :endpoint
def validate
super
assert_present :endpoint
assert_present :pattern
assert_unique [:endpoint, :pattern]
assert_not_superset
assert_not_subset
end
def name
@name = Base64.encode64("#{pattern}|#{endpoint}").gsub("\n","")
end
def to_hash
h = {:pattern => pattern, :name => name, :endpoint => endpoint, :created_at => created_at, :updated_at => updated_at}
super.merge(h)
end
class << self
def find_by_name(name)
pattern, endpoint = Base64.decode64(name).split('|')
find(:pattern => pattern, :endpoint => endpoint).first
end
def watch_list
arr = []
watches = self.all.sort_by(:pattern)
watches.each {|w| arr << w.to_hash}
arr
end
end
private
# Not sure about these next two.
# Could get around patterns changing due to namespace changes
def path_to_pattern
end
def pattern_to_path
end
end
class Watchers
@@agents = []
def self.all(options = {})
options.empty? ? Watcher.all.sort : Watcher.find(options).sort
end
def self.register_agent(agent_class)
@@agents << agent_class
end
def self.agents
@@agents
end
end
end