Class: DigitalOceanInventory::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/digital_ocean_inventory/collector.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Collector

Returns a new instance of Collector.



11
12
13
14
# File 'lib/digital_ocean_inventory/collector.rb', line 11

def initialize(config)
  @config = config
  @client = config.client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/digital_ocean_inventory/collector.rb', line 5

def client
  @client
end

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/digital_ocean_inventory/collector.rb', line 5

def config
  @config
end

Class Method Details

.build(config) ⇒ Object



7
8
9
# File 'lib/digital_ocean_inventory/collector.rb', line 7

def self.build(config)
  new config
end

Instance Method Details

#call(inventory) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/digital_ocean_inventory/collector.rb', line 16

def call(inventory)
  droplets = get_droplets
                .select { |d| select_droplet? d }
                .reject { |d| ignore_droplet? d }

  droplets.each do |droplet|
    groups = droplet_groups droplet
    groups.each { |g| inventory.add_group g }

    inventory.add_host droplet, groups
  end

  inventory
end