Class: Discharger::SetupRunner::CommandFactory
- Inherits:
-
Object
- Object
- Discharger::SetupRunner::CommandFactory
- Defined in:
- lib/discharger/setup_runner/command_factory.rb
Instance Attribute Summary collapse
-
#app_root ⇒ Object
readonly
Returns the value of attribute app_root.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #create_all_commands ⇒ Object
- #create_command(name) ⇒ Object
-
#initialize(config, app_root, logger) ⇒ CommandFactory
constructor
A new instance of CommandFactory.
Constructor Details
#initialize(config, app_root, logger) ⇒ CommandFactory
Returns a new instance of CommandFactory.
10 11 12 13 14 |
# File 'lib/discharger/setup_runner/command_factory.rb', line 10 def initialize(config, app_root, logger) @config = config @app_root = app_root @logger = logger end |
Instance Attribute Details
#app_root ⇒ Object (readonly)
Returns the value of attribute app_root.
8 9 10 |
# File 'lib/discharger/setup_runner/command_factory.rb', line 8 def app_root @app_root end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/discharger/setup_runner/command_factory.rb', line 8 def config @config end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
8 9 10 |
# File 'lib/discharger/setup_runner/command_factory.rb', line 8 def logger @logger end |
Instance Method Details
#create_all_commands ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/discharger/setup_runner/command_factory.rb', line 26 def create_all_commands commands = [] # Create built-in commands from steps if config.steps.any? config.steps.each do |step| command = create_command(step) commands << command if command end else # If no steps specified, create all registered commands CommandRegistry.names.each do |name| command = create_command(name) commands << command if command end end # Create custom commands if config.respond_to?(:custom_steps) && config.custom_steps.any? require_relative "commands/custom_command" config.custom_steps.each do |step_config| command = Commands::CustomCommand.new(config, app_root, logger, step_config) commands << command end end commands end |
#create_command(name) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/discharger/setup_runner/command_factory.rb', line 16 def create_command(name) command_class = CommandRegistry.get(name) return nil unless command_class command_class.new(config, app_root, logger) rescue => e logger&.warn "Failed to create command #{name}: #{e.}" nil end |