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
|
# File 'lib/cf/detect.rb', line 13
def frameworks
info = @client.info
matches = {}
all_frameworks.each do |name, meta|
matched = false
next if meta["detection"].nil?
meta["detection"].first.each do |file, match|
files =
if File.file? @path
if File.fnmatch(file, @path)
[@path]
else
[]
end
else
Dir.glob("#@path/#{file}")
end
unless files.empty?
if match == true
matched = true
elsif match == false
matched = false
break
else
files.each do |f|
contents = File.open(f, &:read)
if contents =~ Regexp.new(match)
matched = true
end
end
end
end
end
if matched
matches[name] = meta
end
end
if matches.size == 1
default = matches.keys.first
end
[matches, default]
end
|