Class: RubyLens::ShowcaseGenerator

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

Constant Summary collapse

DEFAULT_SHOWCASE_NAME =
"rubylens-showcase.html"

Instance Method Summary collapse

Constructor Details

#initialize(path: Dir.pwd, output: nil, lockfile: nil, details: false) ⇒ ShowcaseGenerator

Returns a new instance of ShowcaseGenerator.



11
12
13
14
15
16
# File 'lib/rubylens/showcase_generator.rb', line 11

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

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubylens/showcase_generator.rb', line 18

def call
  root = File.realpath(@path)
  showcase_writer = ShowcaseWriter.new
  output = @output
  if output.nil?
    output = File.join(root, DEFAULT_SHOWCASE_NAME)
    if File.exist?(output) && !showcase_writer.rubylens_showcase?(output)
      raise Error, "default showcase path already exists and is not a RubyLens showcase"
    end
    GitRepository.new(root).exclude_local(output, description: "showcase")
  end
  model, warnings = GenerationPipeline.new(root:, lockfile: @lockfile).call
  output_path = showcase_writer.write(ShowcaseModel.new(model, details: @details).call, output: output)

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