Class: TTY::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/plugins/plugin.rb

Overview

A class responsible for plugin loading

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, gem) ⇒ Plugin

Initialize a Plugin

Parameters:

  • name (String)

    the plugin name

  • gem (Gem::Specification)

    the rubygems gem



19
20
21
22
23
# File 'lib/tty/plugins/plugin.rb', line 19

def initialize(name, gem)
  @name     = name
  @gem      = gem
  @enabled  = false
end

Instance Attribute Details

#gemObject (readonly)

Returns the value of attribute gem.



8
9
10
# File 'lib/tty/plugins/plugin.rb', line 8

def gem
  @gem
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/tty/plugins/plugin.rb', line 6

def name
  @name
end

Instance Method Details

#enabled?Boolean

Check if this plugin has been enabled

Returns:

  • (Boolean)


30
31
32
# File 'lib/tty/plugins/plugin.rb', line 30

def enabled?
  @enabled
end

#load!Object

Load the plugin (require the gem)



37
38
39
40
41
42
43
44
45
46
# File 'lib/tty/plugins/plugin.rb', line 37

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