Class: Licensed::Reporters::NoticesReporter

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

Constant Summary collapse

TEXT_SEPARATOR =
"\n\n#{("-" * 5)}\n\n".freeze
LICENSE_SEPARATOR =
"\n#{("*" * 5)}\n".freeze

Instance Method Summary collapse

Methods inherited from Reporter

#initialize, #report_run, #report_source

Constructor Details

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

Instance Method Details

#notices(report) ⇒ Object

Returns notices information for a dependency report



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/licensed/reporters/notices_reporter.rb', line 51

def notices(report)
  return unless report.target.is_a?(Licensed::Dependency)

  cached_record = report["cached_record"]
  return unless cached_record

  texts = cached_record.licenses.map(&:text)
  texts.concat(cached_record.notices)

  <<~NOTICE
    #{cached_record["name"]}@#{cached_record["version"]}

    #{texts.map(&:strip).reject(&:empty?).compact.join(TEXT_SEPARATOR)}
  NOTICE
end

#report_app(app) ⇒ Object

Reports on an application configuration in a notices command run

app - An application configuration

Returns the result of the yielded method Note - must be called from inside the ‘report_run` scope



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/licensed/reporters/notices_reporter.rb', line 15

def report_app(app)
  super do |report|
    filename = app["shared_cache"] ? "NOTICE.#{app["name"]}" : "NOTICE"
    path = app.cache_path.join(filename)
    shell.info "Writing notices for #{app["name"]} to #{path}"

    result = yield report

    File.open(path, "w") do |file|
      file << "THIRD PARTY NOTICES\n"
      file << LICENSE_SEPARATOR
      file << report.all_reports
                    .map { |r| notices(r) }
                    .compact
                    .join(LICENSE_SEPARATOR)
    end

    result
  end
end

#report_dependency(dependency) ⇒ Object

Reports on a dependency in a notices command run.

dependency - An application dependency

Returns the result of the yielded method Note - must be called from inside the ‘report_run` scope



42
43
44
45
46
47
48
# File 'lib/licensed/reporters/notices_reporter.rb', line 42

def report_dependency(dependency)
  super do |report|
    result = yield report
    shell.warn "* #{report["warning"]}" if report["warning"]
    result
  end
end