Module: VsphereOsIdentifiers

Defined in:
app/lib/vsphere_os_identifiers.rb,
app/lib/vsphere_os_identifiers/os.rb

Defined Under Namespace

Classes: Os

Class Method Summary collapse

Class Method Details

.allObject



17
18
19
# File 'app/lib/vsphere_os_identifiers.rb', line 17

def self.all
  data.map { |os, _| lookup(os) }
end

.dataObject



4
5
6
# File 'app/lib/vsphere_os_identifiers.rb', line 4

def self.data
  @data ||= load_data
end

.find_by(selectors = {}) ⇒ Object



32
33
34
35
36
# File 'app/lib/vsphere_os_identifiers.rb', line 32

def self.find_by(selectors = {})
  result = where(selectors)
  return unless result.any?
  result.first
end

.load_dataObject



13
14
15
# File 'app/lib/vsphere_os_identifiers.rb', line 13

def self.load_data
  YAML.load_file(File.expand_path('vsphere_os_identifiers/data.yaml', __dir__))
end

.lookup(id) ⇒ Object



8
9
10
11
# File 'app/lib/vsphere_os_identifiers.rb', line 8

def self.lookup(id)
  entry = data[id.to_s]
  VsphereOsIdentifiers::Os.new(id, entry) if entry
end

.where(selectors = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'app/lib/vsphere_os_identifiers.rb', line 21

def self.where(selectors = {})
  found = all

  selectors.each do |selector, value|
    next unless selectors.key?(selector) && !value.nil?

    found.select! { |os| os.public_send(selector) && [os.public_send(selector)].flatten.include?(value) }
  end
  found
end