Class: GitCommander::Plugin Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/git_commander/plugin.rb,
lib/git_commander/plugin/loader.rb,
lib/git_commander/plugin/executor.rb

Overview

This class is 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.

Examples:

A simple git plugin

require "git"
git_instance = Git.open(Dir.pwd, log: GitCommander.logger)
GitCommander::Plugin.new(:git, source_instance: git_instance)

Defined Under Namespace

Classes: CommandNotFound, Executor, Loader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, source_instance: nil, registry: nil) ⇒ Plugin

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



30
31
32
33
34
# 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

Instance Attribute Details

#commandsObject

Returns the value of attribute commands.



22
23
24
# File 'lib/git_commander/plugin.rb', line 22

def commands
  @commands
end

#executorObject

Returns the value of attribute executor.



22
23
24
# File 'lib/git_commander/plugin.rb', line 22

def executor
  @executor
end

#nameObject

Returns the value of attribute name.



22
23
24
# File 'lib/git_commander/plugin.rb', line 22

def name
  @name
end

#registryObject

Returns the value of attribute registry.



22
23
24
# File 'lib/git_commander/plugin.rb', line 22

def registry
  @registry
end

Instance Method Details

#find_command(command_name) ⇒ Object

Raises:



36
37
38
39
40
41
42
# 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