class GitCommander::Plugin
@abstract Allows for proxying methods to a plugin from within the context of a Command's block.
A Plugin
provides additional external instances to a Command's @block context. Plugins can define their own inline gems, and can define additional Commands.
@example A simple `git` plugin
require "git" git_instance = Git.open(Dir.pwd, log: GitCommander.logger) GitCommander::Plugin.new(:git, source_instance: git_instance)
Attributes
commands[RW]
executor[RW]
name[RW]
registry[RW]
Public Class Methods
new(name, source_instance: nil, registry: nil)
click to toggle source
Creates a Plugin
object. name
is the name of the plugin.
Options include:
source_instance
- an instance of an object to use in the Command's block context registry
- a Registry
instance for where this Plugin
will be stored for lookup
# File lib/git_commander/plugin.rb, line 30 def initialize(name, source_instance: nil, registry: nil) @name = name @executor = Executor.new(source_instance) if source_instance @registry = registry || GitCommander::Registry.new end
Public Instance Methods
find_command(command_name)
click to toggle source
# File lib/git_commander/plugin.rb, line 36 def find_command(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 for this plugin" if command.nil? command end
Private Instance Methods
logger_tag()
click to toggle source
# File lib/git_commander/plugin.rb, line 46 def logger_tag [name, "plugin"].compact.join(" ") end