camel_snake_keys 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/camel_snake_keys.rb +4 -14
- data/lib/version.rb +1 -1
- data/spec/lib/camel_snake_keys_spec.rb +69 -11
- 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: fd107c36f9563eb3887c4ab9b4805e2b6ee46796
|
4
|
+
data.tar.gz: 9bf618e70270ac65ea28c2ac3346193ba082d526
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8fe1fa43f82a6792ef7e5ac39d3952cf8647d2d326c5939c5f8db64ed70d3c97aa3b9a8d3d122b87fc7f5fa982e5ffacb6ef04b842daaa064ae87f82b2dbd57
|
7
|
+
data.tar.gz: 9598f2d06a0123881eff4afde3970a72fe1151409b3ed1c00f59cd04452f4a2b26a5c3eba6cd6c2532456bf9622e606bbeac3dde684b8d7b94ab74c756aa3406
|
data/CHANGELOG.md
CHANGED
data/lib/camel_snake_keys.rb
CHANGED
@@ -29,13 +29,8 @@ module CamelSnakeKeys
|
|
29
29
|
data.map { |v| snake_keys(v) }
|
30
30
|
elsif data.kind_of? Hash
|
31
31
|
hash = Hash[data.map {|k, v| [if_underscore(k), snake_keys(v)] }]
|
32
|
-
|
33
|
-
|
34
|
-
elsif data.kind_of? HashWithIndifferentAccess || indifference
|
35
|
-
HashWithIndifferentAccess.new( hash )
|
36
|
-
else
|
37
|
-
hash
|
38
|
-
end
|
32
|
+
hash = hash.with_indifferent_access if indifference
|
33
|
+
data.class == Hash ? hash : data.class.new(hash)
|
39
34
|
else
|
40
35
|
data
|
41
36
|
end
|
@@ -46,13 +41,8 @@ module CamelSnakeKeys
|
|
46
41
|
data.map { |v| camel_keys(v) }
|
47
42
|
elsif data.kind_of? Hash
|
48
43
|
hash = Hash[data.map {|k, v| [if_camelize(k), camel_keys(v)] }]
|
49
|
-
|
50
|
-
|
51
|
-
elsif data.kind_of? HashWithIndifferentAccess || indifference
|
52
|
-
HashWithIndifferentAccess.new( hash )
|
53
|
-
else
|
54
|
-
hash
|
55
|
-
end
|
44
|
+
hash = hash.with_indifferent_access if indifference
|
45
|
+
data.class == Hash ? hash : data.class.new(hash)
|
56
46
|
else
|
57
47
|
data
|
58
48
|
end
|
data/lib/version.rb
CHANGED
@@ -4,51 +4,109 @@ RSpec.describe Enumerable do
|
|
4
4
|
|
5
5
|
context "arrays" do
|
6
6
|
let(:snaked) { [[{true=>false, 1=>1.2, 1.2=>1, nil=>2, :foo_bar=>1, "dark_matter"=>[{:dark_energy=>"aBc", "baz_qux"=>"Frob."}]}]] }
|
7
|
-
let(:camelized) { [[{true=>false, 1=>1.2, 1.2=>1, nil=>2, :
|
7
|
+
let(:camelized) { [[{true=>false, 1=>1.2, 1.2=>1, nil=>2, :fooBar=>1, "darkMatter"=>[{:darkEnergy=>"aBc", "bazQux"=>"Frob."}]}]] }
|
8
|
+
|
8
9
|
it "should snake case keys of hashes" do
|
9
10
|
camelized.with_snake_keys.should eq snaked
|
10
11
|
end
|
11
12
|
|
12
13
|
it "should camel case keys of hashes" do
|
13
|
-
snaked.
|
14
|
+
snaked.with_camel_keys.should eq camelized
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
18
|
context "hashes" do
|
18
19
|
let(:snaked) { {false=>true, 1=>1.2, 1.2=>1, nil=>2, :foo_bar=>1, "dark_matter"=>[{:dark_energy=>"aBc", "baz_qux"=>"Frob."}]} }
|
19
|
-
let(:camelized) { {false=>true, 1=>1.2, 1.2=>1, nil=>2, :
|
20
|
+
let(:camelized) { {false=>true, 1=>1.2, 1.2=>1, nil=>2, :fooBar=>1, "darkMatter"=>[{:darkEnergy=>"aBc", "bazQux"=>"Frob."}]} }
|
21
|
+
|
20
22
|
it "should snake case keys of hashes" do
|
21
|
-
camelized.with_snake_keys
|
23
|
+
hash = camelized.with_snake_keys
|
24
|
+
hash.class.should == Hash
|
25
|
+
hash.should eq snaked
|
22
26
|
end
|
23
27
|
|
24
28
|
it "should camel case keys of hashes" do
|
25
|
-
snaked.
|
29
|
+
hash = snaked.with_camel_keys
|
30
|
+
hash.class.should == Hash
|
31
|
+
hash.should eq camelized
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should snake case keys of hashes with indifference" do
|
35
|
+
hash = camelized.with_snake_keys(true)
|
36
|
+
hash.class.should == HashWithIndifferentAccess
|
37
|
+
hash.should eq snaked.with_indifferent_access
|
38
|
+
hash[:foo_bar].should eq hash["foo_bar"]
|
26
39
|
end
|
40
|
+
|
41
|
+
it "should camel case keys of hashes with indifference" do
|
42
|
+
hash = snaked.with_camel_keys(true)
|
43
|
+
hash.class.should == HashWithIndifferentAccess
|
44
|
+
hash.should eq camelized.with_indifferent_access
|
45
|
+
hash["fooBar"].should eq hash[:fooBar]
|
46
|
+
end
|
47
|
+
|
27
48
|
end
|
28
49
|
|
29
50
|
context "hashes with indifferent access" do
|
30
51
|
let(:snaked) { {1.2=>1, 1=>1.2, nil=>2, :foo_bar=>1, "dark_matter"=>[{:dark_energy=>"aBc", "baz_qux"=>"Frob."}]}.with_indifferent_access }
|
31
|
-
let(:camelized) { { 1.2=>1, 1=>1.2, nil=>2, :
|
52
|
+
let(:camelized) { { 1.2=>1, 1=>1.2, nil=>2, :fooBar=>1, "darkMatter"=>[{:darkEnergy=>"aBc", "bazQux"=>"Frob."}]}.with_indifferent_access }
|
32
53
|
|
33
54
|
it "should snake case keys of hashes" do
|
34
|
-
camelized.with_snake_keys
|
55
|
+
hash = camelized.with_snake_keys
|
56
|
+
hash.class.should == HashWithIndifferentAccess
|
57
|
+
hash.should eq snaked
|
35
58
|
end
|
36
59
|
|
37
60
|
it "should camel case keys of hashes" do
|
38
|
-
snaked.
|
61
|
+
hash = snaked.with_camel_keys
|
62
|
+
hash.class.should == HashWithIndifferentAccess
|
63
|
+
hash.should eq camelized
|
39
64
|
end
|
65
|
+
|
66
|
+
it "should snake case keys of hashes with indifference" do
|
67
|
+
hash = camelized.with_snake_keys(true)
|
68
|
+
hash.class.should == HashWithIndifferentAccess
|
69
|
+
hash.should eq snaked
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should camel case keys of hashes with indifference" do
|
73
|
+
hash = snaked.with_camel_keys(true)
|
74
|
+
hash.class.should == HashWithIndifferentAccess
|
75
|
+
hash.should eq camelized
|
76
|
+
end
|
77
|
+
|
40
78
|
end
|
41
79
|
|
42
80
|
context "mashes" do
|
43
81
|
let(:snaked) { Hashie::Mash.new({1.2=>1, 1=>1.2, nil=>2, :foo_bar=>1, "dark_matter"=>[{:dark_energy=>"aBc", "baz_qux"=>"Frob."}]}) }
|
44
|
-
let(:camelized) { Hashie::Mash.new({ 1.2=>1, 1=>1.2, nil=>2, :
|
82
|
+
let(:camelized) { Hashie::Mash.new({ 1.2=>1, 1=>1.2, nil=>2, :fooBar=>1, "darkMatter"=>[{:darkEnergy=>"aBc", "bazQux"=>"Frob."}]}) }
|
45
83
|
|
46
84
|
it "should snake case keys of hashes" do
|
47
|
-
camelized.with_snake_keys
|
85
|
+
hash = camelized.with_snake_keys
|
86
|
+
hash.class.should == Hashie::Mash
|
87
|
+
hash.should eq snaked
|
88
|
+
hash["fooBar"].should == hash[:fooBar]
|
48
89
|
end
|
49
90
|
|
50
91
|
it "should camel case keys of hashes" do
|
51
|
-
snaked.
|
92
|
+
hash = snaked.with_camel_keys
|
93
|
+
hash.class.should == Hashie::Mash
|
94
|
+
hash.should eq camelized
|
95
|
+
hash["foo_bar"].should == hash[:foo_bar]
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should snake case keys of hashes with redundant indifference" do
|
99
|
+
hash = camelized.with_snake_keys(true)
|
100
|
+
hash.class.should == Hashie::Mash
|
101
|
+
hash.should eq snaked
|
102
|
+
hash["foo_bar"].should == hash[:foo_bar]
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should camel case keys of hashes with redundant indifference" do
|
106
|
+
hash = snaked.with_camel_keys(true)
|
107
|
+
hash.class.should == Hashie::Mash
|
108
|
+
hash.should eq camelized
|
109
|
+
hash["foo_bar"].should == hash[:foo_bar]
|
52
110
|
end
|
53
111
|
|
54
112
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: camel_snake_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Buermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|