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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/ntail/uri.rb', line 4
def self.included(base) base.class_eval do
@@default_automatic_files = %w{
xd_receiver.html
crossdomain.xml
favicon.ico
sitemap.xml
robots.txt
}
@@automatic_files = [] ; @@automatic_uris = []
def self.automatic_files()
@@automatic_files.dup
end
def self.automatic_uris()
@@automatic_uris.dup
end
def self.reset_automatic_files()
while !@@automatic_files.empty? ; @@automatic_files.pop ; end
while !@@automatic_uris.empty? ; @@automatic_uris.pop ; end
self.add_automatic_file(@@default_automatic_files)
end
def self.add_automatic_file(automatic_file)
if automatic_file.is_a? Array
automatic_file.each { |file| self.add_automatic_file(file) }
else
(@@automatic_files << automatic_file).uniq!
(@@automatic_uris << Regexp.compile("^\/#{automatic_file}")).uniq!
end
end
self.reset_automatic_files
def self.automatic_uri?(uri)
!@@automatic_uris.detect { |automatic_uri_regexp| uri.match(automatic_uri_regexp) }.nil?
end
@@static_repos = %w{
flash
html
images
javascripts
js
movies
newsletters
pictures
stylesheets
css
xml
}
@@static_uris = @@static_repos.map { |repo| Regexp.compile("^\/#{repo}\/") }
def self.add_static_repo(repo)
@@static_uris << Regexp.compile("^\/#{repo}\/")
end
def self.static_uri?(uri)
!@@static_uris.detect { |static_uri_regexp| uri.match(static_uri_regexp) }.nil?
end
def self.to_uri_s(uri)
uri || "-" end
raise "Class #{base.name} should implement instance method 'uri'" unless base.instance_methods.map(&:to_s).include? 'uri'
end
end
|