Skip to content

Commit 2ca5095

Browse files
committed
refactor: move deep_stringify_keys to Utils
Consolidates utility methods in one place.
1 parent 8842513 commit 2ca5095

2 files changed

Lines changed: 14 additions & 16 deletions

File tree

lib/code_teams/testing.rb

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def self.create_code_team(attributes)
4747

4848
code_team = CodeTeams::Team.new(
4949
config_yml: 'tmp/fake_config.yml',
50-
raw_hash: T.cast(deep_stringify_keys(attributes), T::Hash[T.untyped, T.untyped])
50+
raw_hash: T.cast(Utils.deep_stringify_keys(attributes), T::Hash[T.untyped, T.untyped])
5151
)
5252

5353
code_teams << code_team
@@ -68,21 +68,6 @@ def self.reset!
6868
Thread.current[THREAD_KEY] = []
6969
end
7070

71-
sig { params(value: T.untyped).returns(T.untyped) }
72-
def self.deep_stringify_keys(value)
73-
case value
74-
when Hash
75-
value.each_with_object({}) do |(k, v), acc|
76-
acc[k.to_s] = deep_stringify_keys(v)
77-
end
78-
when Array
79-
value.map { |v| deep_stringify_keys(v) }
80-
else
81-
value
82-
end
83-
end
84-
private_class_method :deep_stringify_keys
85-
8671
module CodeTeamsExtension
8772
extend T::Sig
8873

lib/code_teams/utils.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,18 @@ def underscore(string)
1313
def demodulize(string)
1414
string.split('::').last
1515
end
16+
17+
def deep_stringify_keys(value)
18+
case value
19+
when Hash
20+
value.each_with_object({}) do |(k, v), acc|
21+
acc[k.to_s] = deep_stringify_keys(v)
22+
end
23+
when Array
24+
value.map { |v| deep_stringify_keys(v) }
25+
else
26+
value
27+
end
28+
end
1629
end
1730
end

0 commit comments

Comments
 (0)