Privilege   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A to_s() 0 3 1
1
# frozen_string_literal: true
2
3
require_relative '../mixin/entity'
4
5
module AMA
6
  module Chef
7
    module User
8
      module Model
9
        class Privilege
10
          include Mixin::Entity
11
12
          attribute :type, Symbol
13
          attribute :options, [Hash, K: Symbol, V: [:*, NilClass]], default: {}
14
15
          denormalizer_block do |input, type, context, &block|
16
            input = {} unless input.is_a?(Hash)
17
            target = {}
18
            keys = ['type', 'options', :type, :options]
19
            keys.each do |key|
20
              target[key.to_sym] = input[key] if input[key]
21
            end
22
            target[:options] = {} unless target[:options].is_a?(Hash)
23
            input.each do |key, value|
24
              next if keys.include?(key)
25
              target[:options][key] = value
26
            end
27
            target[:type] = context.path.current.name unless target.key?(:type)
28
            block.call(target, type, context)
29
          end
30
31
          def to_s
32
            "Privilege :#{type}"
33
          end
34
        end
35
      end
36
    end
37
  end
38
end
39