Module: VMC::Plugin

Defined in:
lib/vmc/plugin.rb

Constant Summary collapse

@@plugins =
[]

Class Method Summary collapse

Class Method Details

.load_allObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vmc/plugin.rb', line 11

def self.load_all
  # auto-load gems with 'vmc-plugin' in their name
  matching =
    if Gem::Specification.respond_to? :find_all
      Gem::Specification.find_all do |s|
        s.name =~ /vmc-plugin/
      end
    else
      Gem.source_index.find_name(/vmc-plugin/)
    end

  enabled = Set.new(matching.collect(&:name))

  Gem.loaded_specs["vmc"].dependencies.each do |dep|
    if dep.name =~ /vmc-plugin/ && dep.type == :runtime
      require "#{dep.name}/plugin"
      enabled.delete dep.name
    end
  end

  # allow explicit enabling/disabling of gems via config
  plugins = File.expand_path(VMC::PLUGINS_FILE)
  if File.exists?(plugins) && yaml = YAML.load_file(plugins)
    enabled += yaml["enabled"] if yaml["enabled"]
    enabled -= yaml["disabled"] if yaml["disabled"]
  end

  # load up each gem's 'plugin' file
  #
  # we require this file specifically so people can require the gem
  # without it plugging into VMC
  enabled.each do |gemname|
    require "#{gemname}/plugin"
  end
end