Class: GitCommander::Command::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/git_commander/command/configurator.rb

Overview

Allows configuring a [GitCommander::Command] with a block

Defined Under Namespace

Classes: ConfigurationError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry) ⇒ Configurator

Returns a new instance of Configurator.



11
12
13
# File 'lib/git_commander/command/configurator.rb', line 11

def initialize(registry)
  @registry = registry
end

Instance Attribute Details

#registryObject (readonly)

Returns the value of attribute registry.



9
10
11
# File 'lib/git_commander/command/configurator.rb', line 9

def registry
  @registry
end

Instance Method Details

#configure(name, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/git_commander/command/configurator.rb', line 15

def configure(name, &block)
  new_command = GitCommander::Command.new(name, registry: registry)
  new_command.instance_exec new_command, &block if block_given?
  new_command
rescue StandardError => e
  configuration_error = ConfigurationError.new(e.message)
  configuration_error.set_backtrace e.backtrace
  raise configuration_error
end