class GitCommander::Registry
@abstract Manages available GitCommander
commands
Attributes
commands[RW]
name[RW]
plugins[RW]
Public Class Methods
new()
click to toggle source
# File lib/git_commander/registry.rb, line 16 def initialize @commands = {} @plugins = {} end
Public Instance Methods
find(command_name)
click to toggle source
Looks up a command in the registry
@param [String, Symbol] command_name the name of the command to look up in the
registry
@example Fetch a command from the registry
registry = GitCommander::Registry.new registry.register :wtf registry.find :wtf
@raise [CommandNotFound] when no command is found in the registry @return [GitCommander::Command, run] a command object that responds to run
# File lib/git_commander/registry.rb, line 72 def find(command_name) GitCommander.logger.debug "[#{logger_tag}] looking up command: #{command_name.inspect}" command = commands[command_name.to_s.to_sym] raise CommandNotFound, "[#{logger_tag}] #{command_name} does not exist in the registry" if command.nil? command end
find_plugin(plugin_name)
click to toggle source
# File lib/git_commander/registry.rb, line 80 def find_plugin(plugin_name) GitCommander.logger.debug "[#{logger_tag}] looking up plugin: #{plugin_name.inspect}" plugins[plugin_name.to_s.to_sym] end
load(loader, *args)
click to toggle source
Adds command(s) to the registry using the given loader
@param [CommandLoader] loader the class to use to load with
# File lib/git_commander/registry.rb, line 49 def load(loader, *args) result = loader.new(self).load(*args) if result.success? result.plugins.each { |plugin| register_plugin(plugin) } result.commands.each { |cmd| register_command(cmd) } end result end
register(command_name, **options, &block)
click to toggle source
Adds a command to the registry
@param [String, Symbol] command_name the name of the command to add to the
registry
# File lib/git_commander/registry.rb, line 25 def register(command_name, **options, &block) command = GitCommander::Command.new(command_name.to_sym, registry: self, **options.merge(block: block)) register_command(command) end
register_command(command)
click to toggle source
Adds a pre-built command to the registry @param [Command] command the Command
instance to add to the registry
# File lib/git_commander/registry.rb, line 32 def register_command(command) GitCommander.logger.debug "[#{logger_tag}] Registering command `#{command.name}` with args: #{command.inspect}..." commands[command.name] = command end
register_plugin(plugin)
click to toggle source
Private Instance Methods
logger_tag()
click to toggle source
# File lib/git_commander/registry.rb, line 87 def logger_tag [name, "registry"].compact.join(" ") end