Class: TTY::Plugin
- Inherits:
-
Object
- Object
- TTY::Plugin
- Defined in:
- lib/tty/plugins/plugin.rb
Overview
A class responsible for plugin loading
Instance Attribute Summary collapse
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#gem ⇒ Object
readonly
Returns the value of attribute gem.
-
#gem_name ⇒ Object
readonly
Returns the value of attribute gem_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#enabled? ⇒ Boolean
Check if this plugin has been enabled.
-
#initialize(name, gem) ⇒ Plugin
constructor
Initialize a Plugin.
-
#load! ⇒ Object
Load the plugin (require the gem).
Constructor Details
#initialize(name, gem) ⇒ Plugin
Initialize a Plugin
23 24 25 26 27 28 |
# File 'lib/tty/plugins/plugin.rb', line 23 def initialize(name, gem) @name = name @gem = gem @gem_name = "tty-#{name}" @enabled = false end |
Instance Attribute Details
#enabled ⇒ Object
Returns the value of attribute enabled.
12 13 14 |
# File 'lib/tty/plugins/plugin.rb', line 12 def enabled @enabled end |
#gem ⇒ Object (readonly)
Returns the value of attribute gem.
8 9 10 |
# File 'lib/tty/plugins/plugin.rb', line 8 def gem @gem end |
#gem_name ⇒ Object (readonly)
Returns the value of attribute gem_name.
10 11 12 |
# File 'lib/tty/plugins/plugin.rb', line 10 def gem_name @gem_name end |
#name ⇒ Object (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
35 36 37 |
# File 'lib/tty/plugins/plugin.rb', line 35 def enabled? enabled end |
#load! ⇒ Object
Load the plugin (require the gem)
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tty/plugins/plugin.rb', line 42 def load! begin require gem_name unless enabled? rescue LoadError => error TTY.shell.error("Unable to load plugin #{gem_name} due to #{error}.") rescue => error TTY.shell.error("require '#{gem_name}' failed with #{error}") end @enabled = true end |