pigeon_hole 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pigeon_hole/typed_json.rb +14 -0
- data/spec/integration_spec.rb +38 -0
- 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: 706952f2c2f0ca67d0aafca1db9d9adadfac728e
|
4
|
+
data.tar.gz: 991c0e967ed1c8b1a6863c985d4fe1328c531075
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad6440197be629b26bd60880373a263a78bef20209b301a6fd5466606a0ee769bebdf313ac18eec1894c60c1ae78b1ad823859bfa2569f73cab060e0f7df9079
|
7
|
+
data.tar.gz: 67f9d3926b38a53381e4daf84d7c3d603ac79d786bd8406d42320d55a8ebc01b267bdb6e21daf50b6d11e447746eb1e194436af02ab22ed1798f689153dc7ae4
|
@@ -27,6 +27,16 @@ module PigeonHole
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
class DuplicatedKey < ArgumentError
|
31
|
+
attr_reader :key
|
32
|
+
|
33
|
+
def initialize(key)
|
34
|
+
@key = key
|
35
|
+
|
36
|
+
super("Hash has a duplicated key=#{key}")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
30
40
|
BASIC_TYPES = [
|
31
41
|
NilClass,
|
32
42
|
String,
|
@@ -102,6 +112,10 @@ module PigeonHole
|
|
102
112
|
hash = {}
|
103
113
|
|
104
114
|
value.each do |k, v|
|
115
|
+
if hash.key?(k.to_s) || hash.key?(k.to_sym)
|
116
|
+
raise DuplicatedKey.new(k)
|
117
|
+
end
|
118
|
+
|
105
119
|
begin
|
106
120
|
hash[k] = serialize_value(v)
|
107
121
|
rescue UnsupportedType => e
|
data/spec/integration_spec.rb
CHANGED
@@ -98,6 +98,44 @@ describe "serializing nested hashes" do
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
+
describe "serializing hashes with symbols" do
|
102
|
+
let(:input) do
|
103
|
+
{
|
104
|
+
:foo => :temp
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
subject { PigeonHole.generate(input) }
|
109
|
+
|
110
|
+
it "serializes hash into a string" do
|
111
|
+
result = subject
|
112
|
+
expect(result).to_not be_empty
|
113
|
+
end
|
114
|
+
|
115
|
+
it "hash keys are converted to strings" do
|
116
|
+
result = subject
|
117
|
+
hash = PigeonHole.parse(result)
|
118
|
+
|
119
|
+
expect(hash["foo"]).to eq(input[:foo])
|
120
|
+
expect(hash.keys).to_not include(:foo)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "serializing hashes with duplicated keys" do
|
125
|
+
let(:input) do
|
126
|
+
{
|
127
|
+
:foo => :temp,
|
128
|
+
"foo" => :bar
|
129
|
+
}
|
130
|
+
end
|
131
|
+
|
132
|
+
subject { PigeonHole.generate(input) }
|
133
|
+
|
134
|
+
it "raises an error on generation" do
|
135
|
+
expect { subject }.to raise_error(PigeonHole::TypedJSON::DuplicatedKey)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
101
139
|
describe "preserving order of hashes" do
|
102
140
|
let(:input) do
|
103
141
|
{
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pigeon_hole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Binns
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|