class PluginLoader

Constants

GEM_NAME_PREFIX

Attributes

plugins[R]

Public Class Methods

new() click to toggle source
# File lib/plugin_loader.rb, line 5
def initialize
  @plugins = []
end

Public Instance Methods

find_gems() click to toggle source
# File lib/plugin_loader.rb, line 21
def find_gems
  gem_list.select { |gem| gem.name =~ GEM_NAME_PREFIX }
end
find_plugins() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# File lib/plugin_loader.rb, line 25
def gem_path(name)
  name.tr('-', '/')
end
load_plugins() click to toggle source
# File lib/plugin_loader.rb, line 9
def load_plugins
  find_plugins
end
plugin_klass_name(path) click to toggle source
# 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