rename_keys 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/core_extensions/hash/keys.rb +6 -5
- data/lib/rename_keys/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9117311c21ce4c776a0fdec2df857485bdd684e4
|
4
|
+
data.tar.gz: 10f51c550b80cce77bb839c817a25c1bae9b6fb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7110da626223d7f8dc36ba6a229b920d0e9a2e0dc1e810436048d1efe3a6076266132a5d64e4d3ee3eb42d7f95c2e739e9980d4a00e9f1e7bb2b1118cd1b2a4f
|
7
|
+
data.tar.gz: 3bd2f909738b38cb39b2dd956035b4c9d7de3c0f6be8ee95e0002909355cb62cc195f10aed7147253f1bb9e7e676e928d1dc033460555ad7dcafa518c3045e1c
|
@@ -8,21 +8,22 @@ module CoreExtensions
|
|
8
8
|
module Keys
|
9
9
|
def rename_keys(mapping)
|
10
10
|
result = {}
|
11
|
-
|
11
|
+
|
12
|
+
self.each do |k, v|
|
12
13
|
mapped_key = mapping[k] ? mapping[k] : k
|
13
14
|
|
14
15
|
# If this entry is a deep/nested hash, recursively change key names.
|
15
|
-
result[mapped_key] = v.
|
16
|
+
result[mapped_key] = v.kind_of?(::Hash) ? v.rename_keys(mapping) : v
|
16
17
|
|
17
|
-
result[mapped_key] = v.collect{ |obj| obj.rename_keys(mapping) if obj.
|
18
|
+
result[mapped_key] = v.collect{ |obj| obj.rename_keys(mapping) if obj.kind_of?(::Hash) } if v.kind_of?(::Array)
|
18
19
|
end
|
19
20
|
|
20
21
|
# If used within a Rails project, allow reference by either symbol or string.
|
21
22
|
result.respond_to?(:with_indifferent_access) ? result.with_indifferent_access : result
|
22
|
-
|
23
|
+
end
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
28
|
# Actually monkey-patch the Ruby core Hash class
|
28
|
-
Hash.include CoreExtensions::Hash::Keys
|
29
|
+
Hash.include ::CoreExtensions::Hash::Keys
|
data/lib/rename_keys/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rename_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel LeGrand
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|