Skip to content

Commit faa4538

Browse files
KRED-2061
refactor
1 parent a22de53 commit faa4538

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

lib/xendit_api/json_masker.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def self.mask(json, options = {})
55
return json if json.empty?
66

77
output = JSON.parse(json)
8-
XenditApi::JsonMasker.new(output, options).to_hash
8+
XenditApi::JsonMasker.new(output, options).to_masked
99
rescue JSON::ParserError
1010
json
1111
end
@@ -17,7 +17,7 @@ def initialize(data, options = {})
1717
@full_hide_params = options[:full_hide_params] || []
1818
end
1919

20-
def to_hash
20+
def to_masked
2121
return @data if @mask_params.empty? && @full_hide_params.empty?
2222

2323
case @data
@@ -36,12 +36,14 @@ def to_hash
3636
end
3737
end
3838

39+
def to_hash
40+
filter(@data)
41+
end
42+
3943
private
4044

41-
# rubocop:disable Style/CaseLikeIf
45+
# rubocop:disable Style/CaseLikeIf, Metrics/PerceivedComplexity
4246
def filter(output)
43-
return output unless output.is_a?(Hash)
44-
4547
output.each do |key, value|
4648
output[key] = if value.is_a?(Hash)
4749
XenditApi::JsonMasker.new(value, @options).to_hash
@@ -58,7 +60,7 @@ def filter(output)
5860
end
5961
end
6062
end
61-
# rubocop:enable Style/CaseLikeIf
63+
# rubocop:enable Style/CaseLikeIf, Metrics/PerceivedComplexity
6264

6365
def mask_value(key, value)
6466
return '*****' if @full_hide_params.include?(key)

0 commit comments

Comments
 (0)