Sha256: b6ef26b930a38771c904a028bdeb03c5112b77c7196f5075157e59c7e379eae3

Contents?: true

Size: 1.23 KB

Versions: 6

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Vedeu

  # A class responsible for plugin loading.
  #
  class Plugin

    # @!attribute [r] name
    # @return [String|Symbol]
    attr_reader :name

    # @!attribute [r] gem
    # @return [String]
    attr_reader :gem

    # @!attribute [r] gem_name
    # @return [String]
    attr_reader :gem_name

    # @!attribute [rw] enabled
    # @return [Boolean]
    attr_accessor :enabled
    alias enabled? enabled

    # Returns a new instance of Vedeu::Plugin.
    #
    # @param name [String] The plugin name.
    # @param gem [Gem::Specification] The RubyGems gem.
    # @return [Vedeu::Plugin]
    def initialize(name, gem)
      @name     = name
      @gem      = gem
      @gem_name = "vedeu_#{name}"
      @enabled  = false
    end

    # Load the plugin (require the gem).
    #
    # @macro raise_fatal
    # @return [void]
    def load!
      begin
        require gem_name unless enabled?
      rescue LoadError => error
        raise Vedeu::Error::Fatal,
              "Unable to load plugin #{gem_name} due to #{error}."
      rescue => error
        raise Vedeu::Error::Fatal,
              "require '#{gem_name}' failed with #{error}."
      end

      @enabled = true
    end

  end # Plugin

end # Vedeu

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vedeu-0.8.15 lib/vedeu/plugins/plugin.rb
vedeu-0.8.14 lib/vedeu/plugins/plugin.rb
vedeu-0.8.13 lib/vedeu/plugins/plugin.rb
vedeu-0.8.12 lib/vedeu/plugins/plugin.rb
vedeu-0.8.10 lib/vedeu/plugins/plugin.rb
vedeu-0.8.9 lib/vedeu/plugins/plugin.rb