| Total Complexity | 7 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | # frozen_string_literal: true |
||
| 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 |
||
| 67 |