Class: Mnenv::InstallerFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/mnenv/installer/factory.rb

Overview

Factory for creating installer instances based on source type Uses SourceRegistry for extensibility - new sources just need to register

Defined Under Namespace

Classes: UnknownSourceError

Class Method Summary collapse

Class Method Details

.create(version, source:, target_dir: nil) ⇒ Installer

Create an installer for the given version and source

Parameters:

  • version (String)

    The version to install

  • source (String)

    The source type (e.g., ‘gemfile’, ‘binary’)

  • target_dir (String, nil) (defaults to: nil)

    Optional custom target directory

Returns:

Raises:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mnenv/installer/factory.rb', line 17

def self.create(version, source:, target_dir: nil)
  installer_class = SourceRegistry.installer(source.to_s)

  unless installer_class
    available = SourceRegistry.all_names.join(', ')
    raise Installer::InstallationError,
          "Unknown source: #{source}. Available sources: #{available}"
  end

  installer_class.new(version, source: source, target_dir: target_dir)
rescue SourceRegistry::UnknownSourceError
  available = SourceRegistry.all_names.join(', ')
  raise Installer::InstallationError,
        "Unknown source: #{source}. Available sources: #{available}"
end

.supported?(source) ⇒ Boolean

Check if a source is supported

Parameters:

  • source (String)

    The source type

Returns:

  • (Boolean)


36
37
38
# File 'lib/mnenv/installer/factory.rb', line 36

def self.supported?(source)
  SourceRegistry.registered?(source.to_s)
end

.supported_sourcesArray<String>

Get list of supported sources

Returns:

  • (Array<String>)


42
43
44
# File 'lib/mnenv/installer/factory.rb', line 42

def self.supported_sources
  SourceRegistry.all_names
end