Class: Moose::Inventory::Operations::GroupChildRelations

Inherits:
Object
  • Object
show all
Includes:
OperationEventSupport
Defined in:
lib/moose_inventory/operations/group_child_relations.rb

Instance Method Summary collapse

Constructor Details

#initialize(context:) ⇒ GroupChildRelations

Returns a new instance of GroupChildRelations.



13
14
15
16
17
18
19
# File 'lib/moose_inventory/operations/group_child_relations.rb', line 13

def initialize(context:)
  @context = context
  @cleanup = Moose::Inventory::Operations::GroupCleanup.new(
    context: context,
    emitter: method(:emit)
  )
end

Instance Method Details

#add_children(parent_group:, parent_name:, child_names:, dry_run: false) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/moose_inventory/operations/group_child_relations.rb', line 21

def add_children(parent_group:, parent_name:, child_names:, dry_run: false)
  events = []
  warning_count = 0
  children_dataset = parent_group.children_dataset
  @dry_run = dry_run

  child_names.each do |child_name|
    next if child_name.nil? || child_name.empty?

    warning_count += add_child(parent_group, parent_name, child_name, children_dataset, events)
  end

  emit(events, :dry_run_summary) if dry_run

  operation_result(events: events, warning_count: warning_count)
end

#remove_children(parent_group:, parent_name:, child_names:, delete_orphans: false, dry_run: false) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/moose_inventory/operations/group_child_relations.rb', line 38

def remove_children(parent_group:, parent_name:, child_names:, delete_orphans: false, dry_run: false)
  events = []
  warning_count = 0
  children_dataset = parent_group.children_dataset
  @dry_run = dry_run
  cleanup.dry_run = dry_run

  child_names.each do |child_name|
    next if child_name.nil? || child_name.empty?

    warning_count += remove_child(
      {
        parent_group: parent_group,
        parent_name: parent_name,
        child_name: child_name,
        children_dataset: children_dataset,
        events: events,
        delete_orphans: delete_orphans,
        dry_run: dry_run
      }
    )
  end

  emit(events, :dry_run_summary) if dry_run

  operation_result(events: events, warning_count: warning_count)
end