Class: Moose::Inventory::Operations::AddHosts

Inherits:
Object
  • Object
show all
Defined in:
lib/moose_inventory/operations/add_hosts.rb

Overview

Adds hosts and their optional group associations.

The operation mutates inventory state and returns structured events for the CLI adapter to render. Keeping output out of this class makes the inventory behavior easier to exercise without binding every domain test to progress text.

Defined Under Namespace

Classes: Event, Result

Constant Summary collapse

AUTOMATIC_GROUP =
'ungrouped'

Instance Method Summary collapse

Constructor Details

#initialize(context:) ⇒ AddHosts

Returns a new instance of AddHosts.



18
19
20
# File 'lib/moose_inventory/operations/add_hosts.rb', line 18

def initialize(context:)
  @context = context
end

Instance Method Details

#call(names:, groups:) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/moose_inventory/operations/add_hosts.rb', line 22

def call(names:, groups:)
  events = []
  context.transaction do
    names.each do |name|
      add_host(name, groups, events)
    end
  end
  Result.new(events: events)
end