Class: DigitalOceanInventory::Inventory
- Inherits:
-
Object
- Object
- DigitalOceanInventory::Inventory
- Defined in:
- lib/digital_ocean_inventory/inventory.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
Class Method Summary collapse
Instance Method Summary collapse
- #add_group(name) ⇒ Object
- #add_host(droplet, host_groups = []) ⇒ Object
-
#initialize(config, groups, hosts) ⇒ Inventory
constructor
A new instance of Inventory.
Constructor Details
#initialize(config, groups, hosts) ⇒ Inventory
Returns a new instance of Inventory.
18 19 20 21 22 |
# File 'lib/digital_ocean_inventory/inventory.rb', line 18 def initialize(config, groups, hosts) @config = config @groups = groups @hosts = hosts end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/digital_ocean_inventory/inventory.rb', line 7 def config @config end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
7 8 9 |
# File 'lib/digital_ocean_inventory/inventory.rb', line 7 def groups @groups end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
7 8 9 |
# File 'lib/digital_ocean_inventory/inventory.rb', line 7 def hosts @hosts end |
Class Method Details
Instance Method Details
#add_group(name) ⇒ Object
24 25 26 27 28 29 30 31 |
# 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 = []) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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 |