Class: Pedant::Check
- Inherits:
-
Object
show all
- Defined in:
- lib/pedant/check.rb
Constant Summary
collapse
- @@statuses =
{
:died => 'DIED'.color(:red),
:fail => 'FAIL'.color(:red),
:pass => 'PASS'.color(:green),
:skip => 'SKIP'.color(:green),
:warn => 'WARN'.color(:yellow),
:void => 'VOID'.color(:magenta)
}
- @@levels =
[:error, :warn, :info]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(kb) ⇒ Check
Returns a new instance of Check.
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/pedant/check.rb', line 46
def initialize(kb)
@report = []
@result = :void
@kb = kb
return unless @kb[:test_mode]
self.class.depends.each do |cls|
chk = cls.new(@kb)
chk.run
end
end
|
Instance Attribute Details
#result ⇒ Object
Returns the value of attribute result.
29
30
31
|
# File 'lib/pedant/check.rb', line 29
def result
@result
end
|
Class Method Details
.all ⇒ Object
60
61
62
|
# File 'lib/pedant/check.rb', line 60
def self.all
(@_all ||= [])
end
|
.depends ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/pedant/check.rb', line 82
def self.depends
keys = self.requires
Check.all.reject do |cls|
(cls.provides & keys).empty?
end
end
|
.inherited(cls) ⇒ Object
64
65
66
|
# File 'lib/pedant/check.rb', line 64
def self.inherited(cls)
all << cls
end
|
.initialize! ⇒ Object
42
43
44
|
# File 'lib/pedant/check.rb', line 42
def self.initialize!
Dir.glob(Pedant.lib + 'pedant/checks/*.rb').each { |f| load(f) }
end
|
.provides ⇒ Object
68
69
70
|
# File 'lib/pedant/check.rb', line 68
def self.provides
return []
end
|
.ready?(kb) ⇒ Boolean
76
77
78
79
80
|
# File 'lib/pedant/check.rb', line 76
def self.ready?(kb)
self.requires.reduce(true) do |stat, req|
stat && kb.has_key?(req)
end
end
|
.requires ⇒ Object
72
73
74
|
# File 'lib/pedant/check.rb', line 72
def self.requires
return []
end
|
Instance Method Details
#fail ⇒ Object
114
115
116
|
# File 'lib/pedant/check.rb', line 114
def fail
@result = :fail
end
|
#fatal ⇒ Object
118
119
120
121
|
# File 'lib/pedant/check.rb', line 118
def fatal
report(:error, "This is a fatal error.")
@result = :died
end
|
#name ⇒ Object
109
110
111
112
|
# File 'lib/pedant/check.rb', line 109
def name
self.class.name.gsub(/.*::/, '').gsub(/^Check/, '').gsub(/([A-Z][^A-Z]*)/, ' \1').strip
end
|
#pass ⇒ Object
123
124
125
|
# File 'lib/pedant/check.rb', line 123
def pass
@result = :pass
end
|
#report(level, text = nil) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/pedant/check.rb', line 90
def report(level, text=nil)
if !text.nil?
@report << [level, text]
return
end
level = @@levels.index(level) if level.is_a?(Symbol)
msg = @report.select { |l, t| @@levels.index(l) <= level }.map { |l, t| t }.join("\n")
msg << "\n" unless msg.empty?
msg = "[#{@@statuses[@result]}] #{self.name}\n#{msg}"
return msg
end
|
#skip ⇒ Object
127
128
129
|
# File 'lib/pedant/check.rb', line 127
def skip
@result = :skip
end
|
#warn ⇒ Object
131
132
133
|
# File 'lib/pedant/check.rb', line 131
def warn
@result = :warn
end
|