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
- .all ⇒ Object
- .data ⇒ Object
- .find_by(selectors = {}) ⇒ Object
- .load_data ⇒ Object
- .lookup(id) ⇒ Object
- .where(selectors = {}) ⇒ Object
Class Method Details
.all ⇒ Object
17 18 19 |
# File 'app/lib/vsphere_os_identifiers.rb', line 17 def self.all data.map { |os, _| lookup(os) } end |
.data ⇒ Object
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_data ⇒ Object
13 14 15 |
# File 'app/lib/vsphere_os_identifiers.rb', line 13 def self.load_data YAML.load_file(File.('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 |