Module: Busser::Plugin

Defined in:
lib/busser/plugin.rb

Overview

Plugin loading logic.

Author:

Class Method Summary collapse

Class Method Details

.all_runner_pluginsObject



44
45
46
47
48
# File 'lib/busser/plugin.rb', line 44

def all_runner_plugins
  Gem.find_files('busser/runner_plugin/*.rb').map do |file|
    "busser/runner_plugin/#{File.basename(file).sub(/\.rb$/, '')}"
  end
end

.gem_from_path(plugin_path) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/busser/plugin.rb', line 60

def gem_from_path(plugin_path)
  local_gem_path = "#{File.expand_path(plugin_path, $LOAD_PATH.first)}"
  local_gemspec = File.join(
    File.dirname($LOAD_PATH.first), "busser.gemspec")

  if ! Dir.glob("#{local_gem_path}#{Gem.suffix_pattern}").empty?
    Gem::Specification.load(File.expand_path(local_gemspec))
  else
    Gem::Specification.find_by_path(plugin_path)
  end
end

.require!(plugin_path) ⇒ Object



50
51
52
53
54
# File 'lib/busser/plugin.rb', line 50

def require!(plugin_path)
  require plugin_path
rescue LoadError => e
  Busser::UI.die "Could not load #{plugin_path} (#{e.class}: #{e.message})"
end

.runner_class(klass) ⇒ Object



56
57
58
# File 'lib/busser/plugin.rb', line 56

def runner_class(klass)
  Busser::RunnerPlugin.const_get(klass)
end

.runner_plugin(plugin_name) ⇒ Object



32
33
34
# File 'lib/busser/plugin.rb', line 32

def runner_plugin(plugin_name)
  "busser/runner_plugin/#{plugin_name}"
end

.runner_plugins(plugin_names = nil) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/busser/plugin.rb', line 36

def runner_plugins(plugin_names = nil)
  if plugin_names
    Array(plugin_names).map { |plugin| runner_plugin(plugin) }
  else
    all_runner_plugins
  end
end