Sha256: a47fedc1ecc2869086d3076055f56cbda0e23af7dba45cd7ede52229daf4153c

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

require "set"
require "yaml"

require "vmc/constants"
require "vmc/cli"

module VMC
  module Plugin
    @@plugins = []

    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))

      vmc_gems = Gem.loaded_specs["vmc"]
      ((vmc_gems && vmc_gems.dependencies) || Gem.loaded_specs.values).each do |dep|
        if dep.name =~ /vmc-plugin/
          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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vmc-0.5.0.beta.11 lib/vmc/plugin.rb
vmc-0.5.0.beta.10 lib/vmc/plugin.rb
vmc-0.5.0.beta.7 lib/vmc/plugin.rb