Class: PluginLoader
- Inherits:
-
Object
- Object
- PluginLoader
- Defined in:
- lib/plugin_loader.rb
Constant Summary collapse
- GEM_NAME_PREFIX =
/^ghedsh-/
Instance Attribute Summary collapse
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Instance Method Summary collapse
- #find_gems ⇒ Object
- #find_plugins ⇒ Object
- #gem_list ⇒ Object
- #gem_path(name) ⇒ Object
-
#initialize ⇒ PluginLoader
constructor
A new instance of PluginLoader.
- #load_plugins ⇒ Object
- #plugin_klass_name(path) ⇒ Object
Constructor Details
#initialize ⇒ PluginLoader
Returns a new instance of PluginLoader.
5 6 7 |
# File 'lib/plugin_loader.rb', line 5 def initialize @plugins = [] end |
Instance Attribute Details
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
3 4 5 |
# File 'lib/plugin_loader.rb', line 3 def plugins @plugins end |
Instance Method Details
#find_gems ⇒ Object
21 22 23 |
# File 'lib/plugin_loader.rb', line 21 def find_gems gem_list.select { |gem| gem.name =~ GEM_NAME_PREFIX } end |
#find_plugins ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/plugin_loader.rb', line 13 def find_plugins find_gems.map do |gem| @plugins << { name: gem.name, path: gem_path(gem.name), plugin_klass: plugin_klass_name(gem.name) } end @plugins end |
#gem_list ⇒ Object
39 40 41 42 |
# File 'lib/plugin_loader.rb', line 39 def gem_list Gem.refresh Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('') end |
#gem_path(name) ⇒ Object
25 26 27 |
# File 'lib/plugin_loader.rb', line 25 def gem_path(name) name.tr('-', '/') end |
#load_plugins ⇒ Object
9 10 11 |
# File 'lib/plugin_loader.rb', line 9 def load_plugins find_plugins end |
#plugin_klass_name(path) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/plugin_loader.rb', line 29 def plugin_klass_name(path) # convert gem paths to plugin module. # ghedsh/firstplugin --> Ghedsh::Firstplugin # ghedsh/another_name --> Ghedsh::AnotherName path = gem_path(path) path.split('/').collect do |c| c.split('_').collect(&:capitalize).join end.join('::') end |