Class: Licensed::Reporters::Reporter

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

Direct Known Subclasses

CacheReporter, ListReporter, StatusReporter

Defined Under Namespace

Classes: Report, ReportingError

Instance Method Summary collapse

Constructor Details

#initialize(shell = Licensed::UI::Shell.new) ⇒ Reporter

Returns a new instance of Reporter.



35
36
37
# File 'lib/licensed/reporters/reporter.rb', line 35

def initialize(shell = Licensed::UI::Shell.new)
  @shell = shell
end

Instance Method Details

#report_app(app) ⇒ Object

Generate a report for a licensed app configuration Yields a report object which can be used to view or add data generated for this app

app - An application configuration

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

Raises:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/licensed/reporters/reporter.rb', line 64

def report_app(app)
  raise ReportingError.new("Cannot call report_app with active app context") unless @app_report.nil?
  raise ReportingError.new("Call report_run before report_app") if @run_report.nil?
  result = nil
  @app_report = Report.new(name: app["name"], target: app)
  begin
    result = yield @app_report
  ensure
    @run_report.reports << @app_report
    @app_report = nil
  end

  result
end

#report_dependency(dependency) {|dependency_report| ... } ⇒ Object

Generate a report for a licensed dependency Yields a report object which can be used to view or add data generated for this dependency

dependency - An application dependency

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

Yields:

  • (dependency_report)

Raises:



110
111
112
113
114
115
116
# File 'lib/licensed/reporters/reporter.rb', line 110

def report_dependency(dependency)
  raise ReportingError.new("Call report_source before report_dependency") if @source_report.nil?

  dependency_report = Report.new(name: [@source_report.name, dependency.name].join("."), target: dependency)
  @source_report.reports << dependency_report
  yield dependency_report
end

#report_run(command) ⇒ Object

Generate a report for a licensed command execution Yields a report object which can be used to view or add data generated for this run

Returns the result of the yielded method



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/licensed/reporters/reporter.rb', line 44

def report_run(command)
  result = nil
  @run_report = Report.new(name: nil, target: command)
  begin
    result = yield @run_report
  ensure
    @run_report = nil
  end

  result
end

#report_source(source) ⇒ Object

Generate a report for a licensed dependency source enumerator Yields a report object which can be used to view or add data generated for this dependency source

source - A dependency source enumerator

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

Raises:



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/licensed/reporters/reporter.rb', line 87

def report_source(source)
  raise ReportingError.new("Cannot call report_source with active source context") unless @source_report.nil?
  raise ReportingError.new("Call report_app before report_source") if @app_report.nil?
  result = nil
  @source_report = Report.new(name: [@app_report.name, source.class.type].join("."), target: source)
  begin
    result = yield @source_report
  ensure
    @app_report.reports << @source_report
    @source_report = nil
  end

  result
end