Remote   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 4 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 PrivateKey
10
          class Remote
11
            include Mixin::Entity
12
13
            attribute :id, Symbol
14
            attribute :options, [Hash, K: String, V: [String, Integer]]
15
16
            denormalizer_block do |input, type, context, &block|
17
              input = {} if input.nil?
18
              if input.is_a?(String) || input.is_a?(Symbol)
19
                input = { User: input }
20
              end
21
              raise "Expected Hash, got #{input.class}" unless input.is_a?(Hash)
22
              target = {
23
                options: input[:options] || input['options'] || {},
24
                id: context.path.current.name
25
              }
26
              ['id', :id].each do |key|
27
                target[:id] = input[key] if input[key]
28
              end
29
              input.each do |key, value|
30
                next if %i[id options].include?(key.to_sym)
31
                target[:options][key] = value
32
              end
33
              block.call(target, type, context)
34
            end
35
36
            def initialize(id = nil)
37
              @id = id
38
              @options = {}
39
            end
40
          end
41
        end
42
      end
43
    end
44
  end
45
end
46