Class: Discharger::SetupRunner::CommandRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/discharger/setup_runner/command_registry.rb

Class Method Summary collapse

Class Method Details

.allObject



15
16
17
# File 'lib/discharger/setup_runner/command_registry.rb', line 15

def all
  commands.values
end

.clearObject



23
24
25
# File 'lib/discharger/setup_runner/command_registry.rb', line 23

def clear
  commands.clear
end

.get(name) ⇒ Object



11
12
13
# File 'lib/discharger/setup_runner/command_registry.rb', line 11

def get(name)
  commands[name.to_s]
end

.load_commandsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/discharger/setup_runner/command_registry.rb', line 27

def load_commands
  # Load base command first
  require_relative "commands/base_command"

  # Load all command files from the commands directory
  commands_dir = File.expand_path("commands", __dir__)
  Dir.glob(File.join(commands_dir, "*_command.rb")).each do |file|
    require file
  end

  # Auto-register commands based on naming convention
  Commands.constants.each do |const_name|
    next unless const_name.to_s.end_with?("Command")

    command_class = Commands.const_get(const_name)
    next unless command_class < Commands::BaseCommand
    next if command_class == Commands::BaseCommand

    # Convert class name to command name (e.g., AsdfCommand -> asdf)
    command_name = const_name.to_s.sub(/Command$/, "").gsub(/([A-Z])/, '_\1').downcase.sub(/^_/, "")
    register(command_name, command_class)
  end
end

.namesObject



19
20
21
# File 'lib/discharger/setup_runner/command_registry.rb', line 19

def names
  commands.keys
end

.register(name, command_class) ⇒ Object



7
8
9
# File 'lib/discharger/setup_runner/command_registry.rb', line 7

def register(name, command_class)
  commands[name.to_s] = command_class
end