forked from egbert/project_doctor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
75 lines (60 loc) · 1.16 KB
/
app.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
75
require 'rubygems'
require 'sinatra/reloader'
require 'slim'
class Defects
def self.all
constants.map do |constant|
const_get constant
end
end
class Defect
def self.diagnose(repo)
in_dir(repo) { diagnosis }
end
def self.check_recovery(repo)
in_dir(repo) { diagnosis && recovery }
end
def self.in_dir(repo)
Dir.chdir repo.path
result = yield
Dir.chdir File.dirname(__FILE__)
result
end
end
class CVE20130276
def self.diagnosis
!`Ack "attr_protected :" app/models/`.empty?
end
def self.recovery
!`grep "rails (3.2.12)" Gemfile.lock`.empty?
end
end
end
class Repo
attr_reader :name
def self.all
Dir.glob("./repos/*").map { |path| new name: File.basename(path) }
end
def initialize(options)
@name = options[:name]
end
def path
"./repos/#{name}"
end
def defects
Defects.all.select do |defect|
defect.diagnose self
end
end
def cured_defects
Defects.all.select do |defect|
defect.check_recovery self
end
end
end
class App < Sinatra::Base
get '/' do
@repos = Repo.all
slim :index
end
end