class DigitalOceanInventory::Inventory
Attributes
config[R]
groups[R]
hosts[R]
Public Class Methods
build(config)
click to toggle source
# File lib/digital_ocean_inventory/inventory.rb, line 9 def self.build(config) all = Group.build name: "all", config: config groups = OpenStruct.new all: all hosts = OpenStruct.new new config, groups, hosts end
new(config, groups, hosts)
click to toggle source
# File lib/digital_ocean_inventory/inventory.rb, line 18 def initialize(config, groups, hosts) @config = config @groups = groups @hosts = hosts end
Public Instance Methods
add_group(name)
click to toggle source
# File lib/digital_ocean_inventory/inventory.rb, line 24 def add_group(name) return groups[name] if groups[name] group = Group.build name: name, config: config @groups[name] = group group end
add_host(droplet, host_groups = [])
click to toggle source
# File lib/digital_ocean_inventory/inventory.rb, line 33 def add_host(droplet, host_groups = []) name = droplet.name if hosts[name] host = hosts[name] else host = Host.build droplet: droplet, config: config hosts[name] = host end groups.all << host host_groups.each do |g| if groups[g] groups[g] << host else group = add_group g group << host end end host end