Sha256: 72b16e1911cae81831478579a43c1ac28777e30d67a36e442d8a58b7ec432ba1

Contents?: true

Size: 920 Bytes

Versions: 5

Compression:

Stored size: 920 Bytes

Contents

# encoding: utf-8

module TTY
  # A class responsible for plugin loading
  class Plugin
    attr_reader :name

    attr_reader :gem

    # Initialize a Plugin
    #
    # @param [String] name
    #   the plugin name
    #
    # @param [Gem::Specification] gem
    #   the rubygems gem
    #
    # @api public
    def initialize(name, gem)
      @name     = name
      @gem      = gem
      @enabled  = false
    end

    # Check if this plugin has been enabled
    #
    # @return [Boolean]
    #
    # @api public
    def enabled?
      @enabled
    end

    # Load the plugin (require the gem)
    #
    # @api public
    def load!
      begin
        require name unless enabled?
      rescue LoadError => error
        puts("Unable to load plugin #{name} due to #{error}.")
      rescue => error
        puts("require '#{name}' failed with #{error}")
      end
      @enabled = true
    end
  end # Plugin
end # TTY

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tty-0.8.1 lib/tty/plugins/plugin.rb
tty-0.8.0 lib/tty/plugins/plugin.rb
tty-0.7.0 lib/tty/plugins/plugin.rb
tty-0.6.1 lib/tty/plugins/plugin.rb
tty-0.6.0 lib/tty/plugins/plugin.rb