@@ -34,16 +34,21 @@ def decrypt(contents)
34
34
35
35
# @param [Hash] data
36
36
# @return [Hash]
37
+ # rubocop:disable Metrics/MethodLength
37
38
def decrypt_hash ( data )
38
39
data . each do |key , value |
39
- data [ key ] = if value . is_a? ( Hash ) || value . is_a? ( Array )
40
+ data [ key ] = case value
41
+ when Hash
40
42
decrypt_hash ( value )
43
+ when Array
44
+ value . map { |v | decrypt_hash ( v ) }
41
45
else
42
46
decrypt_string value
43
47
end
44
48
end
45
49
data
46
50
end
51
+ # rubocop:enable Metrics/MethodLength
47
52
48
53
# @param [String] contents The raw YAML string to be encrypted
49
54
# @param [String, nil] original_encrypted_contents The original (encrypted) content to determine which keys have changed
@@ -73,14 +78,18 @@ def encrypt_string(value)
73
78
end
74
79
75
80
# TODO: Fix the complexity of this method
76
- # rubocop:disable Metrics/PerceivedComplexity , Metrics/MethodLength , Metrics/CyclomaticComplexity
81
+ # rubocop:disable Metrics/MethodLength , Metrics/CyclomaticComplexity , Metrics/PerceivedComplexity, Metrics/AbcSize
77
82
# @param [Hash] keys
78
83
# @return [Hash]
79
84
def encrypt_values ( data , original_data = nil )
80
85
data . each do |key , value |
81
- original_encrypted_value = original_data ? original_data [ key ] : nil
82
- data [ key ] = if value . is_a? ( Hash ) || value . is_a? ( Array )
86
+ original_encrypted_value = original_data &.dig ( key )
87
+
88
+ data [ key ] = case value
89
+ when Hash
83
90
encrypt_values ( value , original_encrypted_value )
91
+ when Array
92
+ value . map . with_index { |v , i | encrypt_values ( v , original_encrypted_value &.dig ( i ) ) }
84
93
else
85
94
original_decrypted_value = original_encrypted_value ? decrypt_string ( original_encrypted_value ) : nil
86
95
key_changed = original_decrypted_value . nil? || original_decrypted_value != value
@@ -89,7 +98,7 @@ def encrypt_values(data, original_data = nil)
89
98
end
90
99
data . sort . to_h
91
100
end
92
- # rubocop:enable Metrics/PerceivedComplexity , Metrics/MethodLength , Metrics/CyclomaticComplexity
101
+ # rubocop:enable Metrics/MethodLength , Metrics/CyclomaticComplexity , Metrics/PerceivedComplexity, Metrics/AbcSize
93
102
94
103
# @param [String] value The encrypted value that needs decrypting
95
104
# @return [String]
0 commit comments