File tree Expand file tree Collapse file tree 5 files changed +69
-0
lines changed
Expand file tree Collapse file tree 5 files changed +69
-0
lines changed Original file line number Diff line number Diff line change 22
33require "git_commander/command"
44require "git_commander/logger"
5+ require "git_commander/plugin"
56require "git_commander/registry"
67require "git_commander/system"
78require "git_commander/version"
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require_relative "plugin/executor"
4+
5+ module GitCommander
6+ #
7+ # @abstract Allows for proxying methods to a plugin from within the context of
8+ # a Command's block.
9+ #
10+ # A Plugin provides additional external instances to a Command's @block
11+ # context. Plugins can define their own inline gems, and can define
12+ # additional Commands.
13+ #
14+ # @example Loadable Command file with native `git` plugin
15+ # # This is a unique example of using `plugin` without any options. It
16+ # # uses the `git` plugin provided natively with this gem. Most times you will
17+ # # use a path: "path/to/my/plugin", or url: "https://example.com/myplugin"
18+ # plugin :git
19+ # command :local_branches do |cmd|
20+ # git.branches.local.map(&:name)
21+ # end
22+ #
23+ class Plugin
24+ attr_accessor :executor , :name , :registry
25+
26+ # Creates a Plugin object. +name+ is the name of the plugin.
27+ #
28+ # Options include:
29+ #
30+ # +source_instance+ - an instance of an object to use in the Command's block context
31+ # +registry+ - a Registry instance for where this Plugin will be stored for lookup
32+ def initialize ( name , source_instance : nil , registry : nil )
33+ @name = name
34+ @executor = Executor . new ( source_instance ) if source_instance
35+ @registry = registry || GitCommander ::Registry . new
36+ end
37+ end
38+ end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require "delegate"
4+
5+ module GitCommander
6+ class Plugin
7+ class Executor < SimpleDelegator
8+ end
9+ end
10+ end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ gemfile do
4+ source "https://rubygems.org"
5+ gem "git"
6+ gem "rspec" # This is a stop-gap to allow testing of these in the context of the gem
7+ end
8+
9+ Git . open Dir . pwd , log : GitCommander . logger
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require "spec_helper"
4+
5+ describe GitCommander ::Plugin do
6+ it "initializes an Executor with the provided block" do
7+ source_instance = Object . new
8+ expect ( described_class ::Executor ) . to receive ( :new ) . with ( source_instance )
9+ described_class . new :git , source_instance : source_instance
10+ end
11+ end
You can’t perform that action at this time.
0 commit comments