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

#initialize, #report_dependency

Constructor Details

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

Instance Method Details

#report_app(app) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/licensed/reporters/yaml_reporter.rb', line 16

def report_app(app)
  super do |report|
    result = yield report
    report["sources"] = report.reports.map(&:to_h) if report.reports.any?
    result
  end
end

#report_run(command) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/licensed/reporters/yaml_reporter.rb', line 5

def report_run(command)
  super do |report|
    result = yield report

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

    result
  end
end

#report_source(source) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/licensed/reporters/yaml_reporter.rb', line 24

def report_source(source)
  super do |report|
    result = yield report
    report["dependencies"] = report.reports.map(&:to_h) if report.reports.any?
    result
  end
end

#sanitize(object) ⇒ Object



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

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