Sha256: 692f4356cb82fc7028b14649fcc5e78bad9dc96db38f5e081085b15da2d42cac

Contents?: true

Size: 1.18 KB

Versions: 24

Compression:

Stored size: 1.18 KB

Contents

module Vedeu

  # A class responsible for plugin loading.
  #
  class Plugin

    # @!attribute [r] name
    # @return [String]
    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_method :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).
    #
    # @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

24 entries across 24 versions & 1 rubygems

Version Path
vedeu-0.6.25 lib/vedeu/plugins/plugin.rb
vedeu-0.6.24 lib/vedeu/plugins/plugin.rb
vedeu-0.6.23 lib/vedeu/plugins/plugin.rb
vedeu-0.6.22 lib/vedeu/plugins/plugin.rb
vedeu-0.6.21 lib/vedeu/plugins/plugin.rb
vedeu-0.6.20 lib/vedeu/plugins/plugin.rb
vedeu-0.6.19 lib/vedeu/plugins/plugin.rb
vedeu-0.6.18 lib/vedeu/plugins/plugin.rb
vedeu-0.6.17 lib/vedeu/plugins/plugin.rb
vedeu-0.6.16 lib/vedeu/plugins/plugin.rb
vedeu-0.6.15 lib/vedeu/plugins/plugin.rb
vedeu-0.6.14 lib/vedeu/plugins/plugin.rb
vedeu-0.6.13 lib/vedeu/plugins/plugin.rb
vedeu-0.6.12 lib/vedeu/plugins/plugin.rb
vedeu-0.6.11 lib/vedeu/plugins/plugin.rb
vedeu-0.6.10 lib/vedeu/plugins/plugin.rb
vedeu-0.6.9 lib/vedeu/plugins/plugin.rb
vedeu-0.6.8 lib/vedeu/plugins/plugin.rb
vedeu-0.6.7 lib/vedeu/plugins/plugin.rb
vedeu-0.6.6 lib/vedeu/plugins/plugin.rb