Class: Licensed::Reporters::YamlReporter

Inherits:
Reporter
  • Object
show all
Defined in:
lib/licensed/reporters/yaml_reporter.rb

Instance Method Summary collapse

Methods inherited from Reporter

#begin_report_app, #begin_report_command, #begin_report_dependency, #begin_report_source, #end_report_dependency, #initialize

Constructor Details

This class inherits a constructor from Licensed::Reporters::Reporter

Instance Method Details

#end_report_app(app, report) ⇒ Object

Add source report information to the app report hash

app - An application configuration report - A report object containing information about the app evaluation



18
19
20
# File 'lib/licensed/reporters/yaml_reporter.rb', line 18

def end_report_app(app, report)
  report["sources"] = report.reports.map(&:to_h) if report.reports.any?
end

#end_report_command(command, report) ⇒ Object

Report all information from the command run to the shell as a YAML object

command - The command being run report - A report object containing information about the command run



9
10
11
12
# File 'lib/licensed/reporters/yaml_reporter.rb', line 9

def end_report_command(command, report)
  report["apps"] = report.reports.map(&:to_h) if report.reports.any?
  shell.info sanitize(report.to_h).to_yaml
end

#end_report_source(source, report) ⇒ Object

Add dependency report information to the source report hash

source - A dependency source enumerator report - A report object containing information about the source evaluation



26
27
28
# File 'lib/licensed/reporters/yaml_reporter.rb', line 26

def end_report_source(source, report)
  report["dependencies"] = report.reports.map(&:to_h) if report.reports.any?
end

#sanitize(object) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/licensed/reporters/yaml_reporter.rb', line 30

def sanitize(object)
  case object
  when String, TrueClass, FalseClass, Numeric
    object
  when Array
    object.compact.map { |item| sanitize(item) }
  when Hash
    object.reject { |_, v| v.nil? }
          .map { |k, v| [k.to_s, sanitize(v)] }
          .to_h
  else
    object.to_s
  end
end