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

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

Defined Under Namespace

Classes: Event, Result

Instance Method Summary collapse

Constructor Details

#initialize(context:) ⇒ GroupChildRelations

Returns a new instance of GroupChildRelations.



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

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:) ⇒ Object



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

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

  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

  Result.new(events: events, warning_count: warning_count)
end

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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/moose_inventory/operations/group_child_relations.rb', line 34

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

  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
      }
    )
  end

  Result.new(events: events, warning_count: warning_count)
end