Class: Makit::Cli::Generators::GeneratorFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/makit/cli/generators/generator_factory.rb

Overview

Factory class for creating appropriate generator instances based on project type

Constant Summary collapse

GENERATORS =

Mapping of project types to their corresponding generator classes

{
  "gem" => RubyGenerator,
  "crate" => RustGenerator,
  "nuget" => DotnetGenerator,
  "dotnet" => DotnetGenerator,
  "node" => NodeGenerator,
}.freeze

Class Method Summary collapse

Class Method Details

.available_typesArray<String>

Get list of available project types

Returns:

  • (Array<String>)

    list of supported project types



43
44
45
# File 'lib/makit/cli/generators/generator_factory.rb', line 43

def self.available_types
  GENERATORS.keys
end

.create(type, name, options = {}) ⇒ BaseGenerator

Create a generator instance for the specified project type

Parameters:

  • type (String)

    the project type (gem, crate, nuget, dotnet, node)

  • name (String)

    the project name

  • options (Hash) (defaults to: {})

    additional options for the generator

Returns:

Raises:

  • (ArgumentError)

    if the project type is not supported



29
30
31
32
33
34
35
36
37
38
# File 'lib/makit/cli/generators/generator_factory.rb', line 29

def self.create(type, name, options = {})
  generator_class = GENERATORS[type.downcase]

  unless generator_class
    available_types = GENERATORS.keys.join(", ")
    raise ArgumentError, "Unknown project type '#{type}'. Available types: #{available_types}"
  end

  generator_class.new(name, options)
end