-
-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathhelpers.rb
More file actions
21 lines (19 loc) · 635 Bytes
/
helpers.rb
File metadata and controls
21 lines (19 loc) · 635 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module Config::Integrations::Helpers
def to_dotted_hash(source, target: {}, namespace: nil)
raise ArgumentError, "target must be a hash (given: #{target.class.name})" unless target.kind_of? Hash
prefix = "#{namespace}." if namespace
case source
when Hash
source.each do |key, value|
to_dotted_hash(value, target: target, namespace: "#{prefix}#{key}")
end
when Array
source.each_with_index do |value, index|
to_dotted_hash(value, target: target, namespace: "#{prefix}#{index}")
end
else
target[namespace] = source
end
target
end
end