Planner.plan()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
1
# frozen_string_literal: true
2
3
require 'set'
4
5
::Dir.glob("#{__dir__}/action/**/*.rb").each do |path|
6
  require path
7
end
8
9
require_relative 'planner/account'
10
require_relative 'planner/group'
11
12
module AMA
13
  module Chef
14
    module User
15
      # This class is responsible for creating list of actions required for
16
      # converging from current state to target state
17
      class Planner
18
        def initialize
19
          @accounts = Account.new
20
          @groups = Group.new
21
        end
22
23
        # @param [AMA::Chef::User::Model::State] current_state
24
        # @param [AMA::Chef::User::Model::State] desired_state
25
        def plan(current_state, desired_state)
26
          plan = [
27
            *@accounts.plan(current_state.accounts, desired_state.accounts),
28
            *@groups.plan(current_state.groups, desired_state.groups)
29
          ]
30
          plan.each do |action|
31
            action.class_name = action.class.to_s
32
          end
33
          plan
34
        end
35
      end
36
    end
37
  end
38
end
39