Class: Yarn::Audit::Wrap::AuditParser
- Inherits:
-
Object
- Object
- Yarn::Audit::Wrap::AuditParser
- Defined in:
- lib/yarn/audit/wrap/audit_parser.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #add_ignored(type:, val:) ⇒ Object
- #get_summary ⇒ Object
-
#initialize(opts:) ⇒ AuditParser
constructor
A new instance of AuditParser.
- #parse_json_audit ⇒ Object
- #print_summary ⇒ Object
- #select(&blk) ⇒ Object
Constructor Details
#initialize(opts:) ⇒ AuditParser
Returns a new instance of AuditParser.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/yarn/audit/wrap/audit_parser.rb', line 7 def initialize opts: @opts = opts @ignored = { info: [], low: [], moderate: [], high: [], critical: [] } parse_json_audit end |
Instance Attribute Details
#output ⇒ Object
Returns the value of attribute output.
5 6 7 |
# File 'lib/yarn/audit/wrap/audit_parser.rb', line 5 def output @output end |
Instance Method Details
#add_ignored(type:, val:) ⇒ Object
30 31 32 |
# File 'lib/yarn/audit/wrap/audit_parser.rb', line 30 def add_ignored(type:, val:) @ignored[type.to_sym] << val end |
#get_summary ⇒ Object
44 45 46 |
# File 'lib/yarn/audit/wrap/audit_parser.rb', line 44 def get_summary @output.detect { |item| item["type"] == "auditSummary" } || {} end |
#parse_json_audit ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/yarn/audit/wrap/audit_parser.rb', line 19 def parse_json_audit audit_json = @opts[:audit_json] @output = if File.exist?(audit_json) File.readlines(audit_json).map do |line| JSON.parse(line) end else [] end end |
#print_summary ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/yarn/audit/wrap/audit_parser.rb', line 48 def print_summary puts "\nOriginal Yarn Audit:" s = get_summary["data"] || {} s.each { |k, v| puts "#{k.to_s.rjust(23)}: #{v.inspect}" } puts "\nSkipped vulnerabilities:" @ignored.each do |k, v| puts "#{k.to_s.rjust(23)}: #{v.size}" end end |
#select(&blk) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/yarn/audit/wrap/audit_parser.rb', line 34 def select(&blk) if @output @output.select do |item| yield item if item["type"] == "auditAdvisory" end else [] end end |