Class: DigitalOceanInventory::Serializer

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Serializer

Returns a new instance of Serializer.



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

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

Class Method Details

.build(config) ⇒ Object



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

def self.build(config)
  new config
end

Instance Method Details

#call(inventory) ⇒ Object



15
16
17
18
19
20
# File 'lib/digital_ocean_inventory/serializer.rb', line 15

def call(inventory)
  meta = { _meta: { hostvars: hostvars(inventory) } }
  data = groups(inventory).merge meta

  JSON.dump data
end