Class: Denmark
- Inherits:
-
Object
show all
- Defined in:
- lib/denmark.rb,
lib/denmark/version.rb
Defined Under Namespace
Classes: Plugins, Repository
Constant Summary
collapse
- VERSION =
'0.0.2'
Class Method Summary
collapse
Class Method Details
.config(*args) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/denmark.rb', line 18
def self.config(*args)
if args.empty?
@config
else
@config.dig(*args)
end
end
|
.config=(arg) ⇒ Object
14
15
16
17
|
# File 'lib/denmark.rb', line 14
def self.config=(arg)
raise "Requires a Hash to set config, not a #{arg.class}" unless arg.is_a? Hash
@config = arg
end
|
.evaluate(slug, options) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/denmark.rb', line 32
def self.evaluate(slug, options)
@options = options
slug.sub!('/', '-')
begin
mod = PuppetForge::Module.find(slug)
rescue Faraday::BadRequestError, Faraday::ResourceNotFound
raise "The module `#{slug}` was not found on the Puppet Forge."
end
repo = Denmark::Repository.new(mod.homepage_url)
data = Denmark::Plugins.new(options).run(mod, repo)
case options[:format]
when 'json'
puts JSON.pretty_generate(data)
when 'human'
generate_report(data)
else
raise 'unknown format'
end
end
|
.generate_report(data) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/denmark.rb', line 54
def self.generate_report(data)
if data.empty?
puts "Congrats, no smells discovered"
else
puts
[:red, :orange, :yellow, :green].each do |severity|
alerts = data.select {|i| i[:severity] == severity}
next unless alerts.size > 0
puts "[#{severity.upcase}] alerts:".colorize(severity)
alerts.each do |alert|
puts " #{alert[:message]}"
puts " > #{alert[:explanation]}" if @options[:detail]
end
puts
end
end
end
|
.list(options) ⇒ Object
27
28
29
30
|
# File 'lib/denmark.rb', line 27
def self.list(options)
puts
puts Denmark::Plugins.new(options).list
end
|