Class: Vmpooler::Providers

Inherits:
Object
  • Object
show all
Defined in:
lib/vmpooler/providers.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.installed_providersArray



24
25
26
# File 'lib/vmpooler/providers.rb', line 24

def self.installed_providers
  new.vmpooler_provider_gem_list.map(&:name)
end

.load_all_providersArray

ie. [“lib/vmpooler/providers/base.rb”, “lib/vmpooler/providers/dummy.rb”, “lib/vmpooler/providers/vsphere.rb”] although these files can come from any gem



19
20
21
# File 'lib/vmpooler/providers.rb', line 19

def self.load_all_providers
  new.load_from_gems
end

.load_by_name(names) ⇒ Array

ie. [“lib/vmpooler/providers/base.rb”, “lib/vmpooler/providers/dummy.rb”, “lib/vmpooler/providers/vsphere.rb”]



10
11
12
13
14
# File 'lib/vmpooler/providers.rb', line 10

def self.load_by_name(names)
  names = Array(names)
  instance = new
  names.map { |name| instance.load_from_gems(name) }.flatten
end

Instance Method Details

#load_from_gems(name = nil) ⇒ Array[String]

Internal: Find any gems containing vmpooler provider plugins and load the main file in them.



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/vmpooler/providers.rb', line 37

def load_from_gems(name = nil)
  paths = gem_directories.map do |gem_path|
    # we don't exactly know if the provider name matches the main file name that should be loaded
    # so we use globs to get everything like the name
    # this could mean that vsphere5 and vsphere6 are loaded when only vsphere5 is used
    Dir.glob(File.join(gem_path, "*#{name}*.rb")).sort.each do |file|
      require file
    end
  end
  paths.flatten
end

#vmpooler_provider_gem_listArray



29
30
31
# File 'lib/vmpooler/providers.rb', line 29

def vmpooler_provider_gem_list
  gemspecs.find_all { |spec| File.directory?(File.join(spec.full_gem_path, provider_path)) } + included_lib_dirs
end