| Total Complexity | 5 | 
| Total Lines | 27 | 
| Duplicated Lines | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | # frozen_string_literal: true | ||
| 15 | class Privilege | ||
| 16 | # @param [AMA::Chef::User::Model::Account] account | ||
| 17 |             # @param [Hash{Symbol, AMA::Chef::User::Model::Privilege}] current_state | ||
| 18 |             # @param [Hash{Symbol, AMA::Chef::User::Model::Privilege}] desired_state | ||
| 19 | def plan(account, current_state, desired_state) | ||
| 20 | actions = (current_state.keys | desired_state.keys).map do |key| | ||
| 21 | process(account, current_state[key], desired_state[key]) | ||
| 22 | end | ||
| 23 | actions.push(ns::Purge.new(account)) if desired_state.empty? | ||
| 24 | actions | ||
| 25 | end | ||
| 26 | |||
| 27 | # @param [AMA::Chef::User::Model::Account] account | ||
| 28 | # @param [AMA::Chef::User::Model::Privilege] current_state | ||
| 29 | # @param [AMA::Chef::User::Model::Privilege] desired_state | ||
| 30 | def process(account, current_state, desired_state) | ||
| 31 | if desired_state.nil? | ||
| 32 | ns::Revoke.new(account, current_state) | ||
| 33 | else | ||
| 34 | ns::Grant.new(account, desired_state) | ||
| 35 | end | ||
| 36 | end | ||
| 37 | |||
| 38 | def ns | ||
| 39 | ::AMA::Chef::User::Action::Account::Privilege | ||
| 40 | end | ||
| 41 | end | ||
| 42 | end | ||
| 47 |