Class: TTY::Plugins
- Inherits:
-
Object
- Object
- TTY::Plugins
- Defined in:
- lib/tty/plugins.rb
Overview
A class responsible for managing plugins installation
Constant Summary collapse
- PLUGIN_PREFIX =
'tty'
Instance Attribute Summary collapse
-
#plugins ⇒ Object
writeonly
Sets the attribute plugins.
Instance Method Summary collapse
-
#find ⇒ Object
private
Find all installed TTY plugins and store them.
-
#initialize ⇒ Plugins
constructor
Initialize the Plugins.
-
#load ⇒ Object
Load all plugins that are not enabled.
-
#names ⇒ Object
Return a list of all plugin names as strings.
-
#register(name, plugin = false) ⇒ Object
Register plugin with name in internal array.
Constructor Details
#initialize ⇒ Plugins
Initialize the Plugins
14 15 16 |
# File 'lib/tty/plugins.rb', line 14 def initialize @plugins = [] end |
Instance Attribute Details
#plugins=(value) ⇒ Object
Sets the attribute plugins
8 9 10 |
# File 'lib/tty/plugins.rb', line 8 def plugins=(value) @plugins = value end |
Instance Method Details
#find ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Find all installed TTY plugins and store them
43 44 45 46 47 48 49 50 51 |
# File 'lib/tty/plugins.rb', line 43 def find Gem.refresh Gem::Specification.each do |gem| next unless gem.name =~ /^#{PLUGIN_PREFIX}/ plugin_name = gem.name[/^#{PLUGIN_PREFIX}-(.*)/, 1] register(plugin_name, Plugin.new(plugin_name, gem)) end plugins end |
#load ⇒ Object
Load all plugins that are not enabled
21 22 23 24 25 |
# File 'lib/tty/plugins.rb', line 21 def load plugins.each do |plugin| plugin.load! unless plugin.enabled? end end |
#names ⇒ Object
Return a list of all plugin names as strings
56 57 58 59 60 61 |
# File 'lib/tty/plugins.rb', line 56 def names plugins.reduce({}) do |hash, plugin| hash[plugin.name] = plugin hash end end |
#register(name, plugin = false) ⇒ Object
Register plugin with name in internal array
34 35 36 37 38 |
# File 'lib/tty/plugins.rb', line 34 def register(name, plugin = false) if plugin && !loaded?(name) plugins << plugin end end |