Remove   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 100 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A apply() 14 14 1
A initialize() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
# frozen_string_literal: true
2
3
require_relative '../../../action'
4
5
module AMA
6
  module Chef
7
    module User
8 View Code Duplication
      class Action
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9
        module Account
10
          module PrivateKey
11
            class Remove < Action
12
              attr_accessor :account
13
              attr_accessor :key
14
15
              # @param [AMA::Chef::User::Model::Account] account
16
              # @param [AMA::Chef::User::Model::PrivateKey] key
17
              def initialize(account, key)
18
                @account = account
19
                @key = key
20
              end
21
22
              def apply(resource_factory)
23
                account = @account
24
                key = @key
25
                name = "#{account.id}:#{key.owner}:#{key.id}"
26
                content = (key.content || '').to_s
27
                resource_factory.ssh_private_key name do
28
                  id key.id.to_s
29
                  user account.id.to_s
30
                  # TODO: remove when https://github.com/ama-team/cookbook-ssh-private-keys/issues/2
31
                  # is resolved
32
                  content content
33
                  action :remove
34
                end
35
              end
36
            end
37
          end
38
        end
39
      end
40
    end
41
  end
42
end
43