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(path: Dir.pwd, output: nil, lockfile: nil) ⇒ Generator

Returns a new instance of Generator.



27
28
29
30
31
# File 'lib/rubylens/generator.rb', line 27

def initialize(path: Dir.pwd, output: nil, lockfile: nil)
  @path = path
  @output = output
  @lockfile = lockfile
end

Instance Method Details

#callObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rubylens/generator.rb', line 33

def call
  root = File.realpath(@path)
  report_writer = ReportWriter.new
  output = @output
  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 = GenerationPipeline.new(root:, lockfile: @lockfile).call
  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