Class: RubyLens::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/rubylens/generator.rb

Constant Summary collapse

DEFAULT_REPORT_NAME =
"rubylens-report.html"

Instance Method Summary collapse

Constructor Details

#initialize(manifest_builder: Index::Manifest, adapter: Index::RubydexAdapter.new, model_builder: ArtModelBuilder.new, report_writer: ReportWriter.new, pipeline: nil) ⇒ Generator

Returns a new instance of Generator.



28
29
30
31
32
33
34
35
36
37
# File 'lib/rubylens/generator.rb', line 28

def initialize(
  manifest_builder: Index::Manifest,
  adapter: Index::RubydexAdapter.new,
  model_builder: ArtModelBuilder.new,
  report_writer: ReportWriter.new,
  pipeline: nil
)
  @pipeline = pipeline || GenerationPipeline.new(manifest_builder:, adapter:, model_builder:)
  @report_writer = report_writer
end

Instance Method Details

#call(path: Dir.pwd, output: nil, lockfile: nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rubylens/generator.rb', line 39

def call(path: Dir.pwd, output: nil, lockfile: nil)
  root = File.realpath(path)
  if output.nil?
    output = File.join(root, DEFAULT_REPORT_NAME)
    if File.exist?(output) && !@report_writer.rubylens_report?(output)
      raise Error, "default report path already exists and is not a RubyLens report"
    end
    GitRepository.new(root).exclude_local(output)
  end
  model, warnings = @pipeline.call(root:, lockfile:)
  output_path = @report_writer.write(model, output: output)

  RubyLens::Result.new(output_path: output_path, counts: model.fetch("totals").freeze, warnings:)
rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP => error
  raise Error, error.message
end