State   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 50
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A account() 0 3 1
A initialize() 0 5 1
A group() 0 3 1
A account! 0 9 2
A group! 0 8 2
1
# frozen_string_literal: true
2
3
require_relative '../mixin/entity'
4
5
require_relative 'account'
6
require_relative 'group'
7
8
module AMA
9
  module Chef
10
    module User
11
      module Model
12
        # Represents complete node state
13
        class State
14
          include Mixin::Entity
15
16
          # !@attribute groups
17
          #   @return [Hash{Symbol, Group}]
18
          attribute :groups, [Hash, K: Symbol, V: Group], default: {}
19
          # !@attribute accounts
20
          #   @return [Hash{Symbol, Account}]
21
          attribute :accounts, [Hash, K: Symbol, V: Account], default: {}
22
          # !@attribute version
23
          #   @return [Integer]
24
          attribute :version, Integer, default: 1
25
26
          def initialize
27
            @groups = {}
28
            @accounts = {}
29
            @version = 1
30
          end
31
32
          # @return [AMA::Chef::User::Model::Account]
33
          def account!(id)
34
            id = id.to_sym
35
            unless accounts[id]
36
              accounts[id] = Account.new
37
              accounts[id].id = id
38
              accounts[id].policy = Policy::NONE
39
            end
40
            account(id)
41
          end
42
43
          # @return [AMA::Chef::User::Model::Account]
44
          def account(id)
45
            accounts[id.to_sym]
46
          end
47
48
          # @return [AMA::Chef::User::Model::Group]
49
          def group!(id)
50
            id = id.to_sym
51
            unless groups[id]
52
              groups[id] = Group.new
53
              groups[id].id = id
54
            end
55
            group(id)
56
          end
57
58
          # @return [AMA::Chef::User::Model::Group]
59
          def group(id)
60
            groups[id.to_sym]
61
          end
62
        end
63
      end
64
    end
65
  end
66
end
67