Class: Licensed::Reporters::NoticesReporter
- 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
-
#app_notices_path(app) ⇒ Object
Returns the path to an applications notices file.
-
#begin_report_app(app, report) ⇒ Object
Reports the start of an application evaluation in a notices command run.
-
#end_report_app(app, report) ⇒ Object
Writes the licensing information gathered during the application evaluation to a notices file.
-
#end_report_dependency(dependency, report) ⇒ Object
Reports on a dependency in a notices command run.
-
#end_report_source(source, report) ⇒ Object
Reports any warnings encountered during the run.
-
#notices(report) ⇒ Object
Returns notices information for a dependency report.
Methods inherited from Reporter
#begin_report_command, #begin_report_dependency, #begin_report_source, #end_report_command, #initialize
Constructor Details
This class inherits a constructor from Licensed::Reporters::Reporter
Instance Method Details
#app_notices_path(app) ⇒ Object
Returns the path to an applications notices file
80 81 82 83 |
# File 'lib/licensed/reporters/notices_reporter.rb', line 80 def app_notices_path(app) filename = app["shared_cache"] ? "NOTICE.#{app["name"]}" : "NOTICE" app.cache_path.join(filename) end |
#begin_report_app(app, report) ⇒ Object
Reports the start of an application evaluation in a notices command run
app - An application configuration report - A report object containing information about the app evaluation
13 14 15 |
# File 'lib/licensed/reporters/notices_reporter.rb', line 13 def begin_report_app(app, report) shell.info "Writing notices for #{app["name"]} to #{app_notices_path(app)}" end |
#end_report_app(app, report) ⇒ Object
Writes the licensing information gathered during the application evaluation to a notices file
app - An application configuration report - A report object containing information about the app evaluation
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/licensed/reporters/notices_reporter.rb', line 22 def end_report_app(app, report) File.open(app_notices_path(app), "w") do |file| file << "THIRD PARTY NOTICES\n" file << LICENSE_SEPARATOR file << report.all_reports .map { |r| notices(r) } .compact .join(LICENSE_SEPARATOR) end end |
#end_report_dependency(dependency, report) ⇒ Object
Reports on a dependency in a notices command run.
dependency - An application dependency report - A report object containing information about the dependency evaluation
47 48 49 50 51 |
# File 'lib/licensed/reporters/notices_reporter.rb', line 47 def end_report_dependency(dependency, report) report.warnings.each do |warning| shell.warn "* #{report.name}: #{warning}" end end |
#end_report_source(source, report) ⇒ Object
Reports any warnings encountered during the run.
source - A dependency source enumerator report - A report object containing information about the source evaluation
37 38 39 40 41 |
# File 'lib/licensed/reporters/notices_reporter.rb', line 37 def end_report_source(source, report) report.warnings.each do |warning| shell.warn "* #{report.name}: #{warning}" end end |
#notices(report) ⇒ Object
Returns notices information for a dependency report
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/licensed/reporters/notices_reporter.rb', line 54 def notices(report) return unless report.target.is_a?(Licensed::Dependency) record = report["record"] return unless record texts = record.licenses.map(&:text) record.notices.each do |notice| case notice when Hash texts << notice["text"] when String texts << notice else shell.warn "* unable to parse notices for #{report.target.name}" end end <<~NOTICE #{record["name"]}@#{record["version"]} #{texts.map(&:strip).reject(&:empty?).compact.join(TEXT_SEPARATOR)} NOTICE end |