Class: GitCommander::Command::Loaders::Raw Abstract

Inherits:
Loader
  • Object
show all
Defined in:
lib/git_commander/command/loaders/raw.rb

Overview

This class is abstract.

Handles loading commands from raw strings

Defined Under Namespace

Classes: CommandParseError

Instance Attribute Summary collapse

Attributes inherited from Loader

#registry, #result

Instance Method Summary collapse

Methods inherited from Loader

#initialize, #system

Constructor Details

This class inherits a constructor from GitCommander::Loader

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



14
15
16
# File 'lib/git_commander/command/loaders/raw.rb', line 14

def content
  @content
end

Instance Method Details

#command(name, &block) ⇒ Object



30
31
32
33
34
# File 'lib/git_commander/command/loaders/raw.rb', line 30

def command(name, &block)
  result.commands << Configurator.new(registry).configure(name, &block)
rescue Configurator::ConfigurationError => e
  result.errors << e
end

#load(content = "") ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/git_commander/command/loaders/raw.rb', line 16

def load(content = "")
  @content = content
  instance_eval @content
  result
# In this case, since we're evaluating raw IO in the context of this
# instance, we need to catch a wider range of exceptions.  Otherwise,
# syntax errors would blow this up.
rescue Exception => e # rubocop:disable Lint/RescueException
  parse_error = CommandParseError.new(e.message)
  parse_error.set_backtrace e.backtrace
  result.errors << parse_error
  result
end

#plugin(name, **options) ⇒ Object



36
37
38
39
# File 'lib/git_commander/command/loaders/raw.rb', line 36

def plugin(name, **options)
  plugin_result = GitCommander::Plugin::Loader.new(registry).load(name, **options)
  result.plugins |= plugin_result.plugins
end