Class: GitCommander::Plugin::Loader Abstract
- Defined in:
- lib/git_commander/plugin/loader.rb
Overview
This class is abstract.
Handles loading native plugins by name.
Defined Under Namespace
Classes: LoadError, NotFoundError
Constant Summary collapse
- NATIVE_PLUGIN_DIR =
File.(File.join(__dir__, "..", "plugins"))
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Loader
Instance Method Summary collapse
- #command(name, &block) ⇒ Object
-
#initialize(registry) ⇒ Loader
constructor
A new instance of Loader.
- #load(name) ⇒ Object
- #plugin(name, **options) ⇒ Object
- #resolve_content(native_name_or_filename) ⇒ Object
- #resolve_plugin_name(native_name_or_filename) ⇒ Object
Methods inherited from Loader
Constructor Details
#initialize(registry) ⇒ Loader
Returns a new instance of Loader.
17 18 19 20 |
# File 'lib/git_commander/plugin/loader.rb', line 17 def initialize(registry) @commands = [] super end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
15 16 17 |
# File 'lib/git_commander/plugin/loader.rb', line 15 def commands @commands end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
15 16 17 |
# File 'lib/git_commander/plugin/loader.rb', line 15 def content @content end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/git_commander/plugin/loader.rb', line 15 def name @name end |
Instance Method Details
#command(name, &block) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/git_commander/plugin/loader.rb', line 51 def command(name, &block) GitCommander.logger.debug("Loading command :#{name} from plugin #{@name}") @commands << Command::Configurator.new(registry).configure("#{plugin_name_formatted_for_cli}:#{name}".to_sym, &block) rescue Command::Configurator::ConfigurationError => e result.errors << e end |
#load(name) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/git_commander/plugin/loader.rb', line 22 def load(name) @plugin = GitCommander::Plugin.new( resolve_plugin_name(name), source_instance: instance_eval(resolve_content(name)) ) @plugin.commands = @commands result.plugins << @plugin result.commands |= @commands result rescue Errno::ENOENT, Errno::EACCES => e handle_error LoadError, e rescue StandardError => e handle_error NotFoundError, e end |
#plugin(name, **options) ⇒ Object
58 59 60 61 |
# File 'lib/git_commander/plugin/loader.rb', line 58 def plugin(name, **) plugin_result = GitCommander::Plugin::Loader.new(registry).load(name, **) result.plugins |= plugin_result.plugins end |
#resolve_content(native_name_or_filename) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/git_commander/plugin/loader.rb', line 43 def resolve_content(native_name_or_filename) if native_name_or_filename.is_a? Symbol return @content = File.read("#{NATIVE_PLUGIN_DIR}/#{native_name_or_filename}.rb") end @content = File.read(native_name_or_filename) end |
#resolve_plugin_name(native_name_or_filename) ⇒ Object
37 38 39 40 41 |
# File 'lib/git_commander/plugin/loader.rb', line 37 def resolve_plugin_name(native_name_or_filename) return @name = native_name_or_filename if native_name_or_filename.is_a? Symbol @name = File.basename(native_name_or_filename).split(".").first.to_sym end |