pigeon_hole 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pigeon_hole/json_hash.rb +16 -0
- data/lib/pigeon_hole/typed_json.rb +8 -1
- data/lib/pigeon_hole.rb +1 -0
- data/spec/integration_spec.rb +35 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a331a8c3a34ef063b9865ea99351e80a0fead73
|
4
|
+
data.tar.gz: 9290c4aecc7891840b9b1b9c7b455ee7d47ea450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab39e9fca4485d6930c56c577d1e82df2a7fdbfcf84dc19e3cfda036aca9cb3e62c80bad3937096e158dac17e21d65b24e267a8766efe0642eee5f66281d9d76
|
7
|
+
data.tar.gz: 89bf8713b463eabf430011528bec96a9183f121b388f07df91a3774a23d39f6da0c27f758d28d0f77f801cfdbd0a469f4907f4b482e419bbf80beaa4b5e39528
|
@@ -73,6 +73,13 @@ module PigeonHole
|
|
73
73
|
when Hash
|
74
74
|
if deserializer = DESERIALIZERS[value[TYPE_KEY]]
|
75
75
|
deserializer.deserialize(value)
|
76
|
+
elsif value[TYPE_KEY] == JSONHash::TYPE_VALUE
|
77
|
+
hash = JSONHash.deserialize(value)
|
78
|
+
hash.each do |k,v|
|
79
|
+
hash[k] = deserialize_value(v)
|
80
|
+
end
|
81
|
+
|
82
|
+
hash
|
76
83
|
else
|
77
84
|
value.each do |k, v|
|
78
85
|
value[k] = deserialize_value(v)
|
@@ -102,7 +109,7 @@ module PigeonHole
|
|
102
109
|
end
|
103
110
|
end
|
104
111
|
|
105
|
-
hash
|
112
|
+
JSONHash.serialize(hash)
|
106
113
|
when Array
|
107
114
|
value.each_with_index.map do |av, i|
|
108
115
|
begin
|
data/lib/pigeon_hole.rb
CHANGED
data/spec/integration_spec.rb
CHANGED
@@ -97,6 +97,41 @@ describe "serializing nested hashes" do
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
+
describe "preserving order of hashes" do
|
101
|
+
let(:input) do
|
102
|
+
{
|
103
|
+
"zzz" => random_time,
|
104
|
+
"aaa" => :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 "can be deserialized to a symbol" do
|
116
|
+
result = subject
|
117
|
+
hash = PigeonHole.parse(result)
|
118
|
+
|
119
|
+
expect(hash).to eq(input)
|
120
|
+
expect(hash.keys.first).to eq("zzz")
|
121
|
+
expect(hash.keys.at(1)).to eq("aaa")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "can deserialize standard json hashes" do
|
126
|
+
let(:json_string) { '{ "foo": 1 }' }
|
127
|
+
|
128
|
+
it "can be deserialized to a symbol" do
|
129
|
+
hash = PigeonHole.parse(json_string)
|
130
|
+
|
131
|
+
expect(hash).to eq({ 'foo' => 1})
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
100
135
|
describe "serializing custom type" do
|
101
136
|
CustomType = Struct.new(:name)
|
102
137
|
|
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.3
|
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-08-
|
11
|
+
date: 2016-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -18,6 +18,7 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- lib/pigeon_hole.rb
|
20
20
|
- lib/pigeon_hole/json_date.rb
|
21
|
+
- lib/pigeon_hole/json_hash.rb
|
21
22
|
- lib/pigeon_hole/json_symbol.rb
|
22
23
|
- lib/pigeon_hole/json_time.rb
|
23
24
|
- lib/pigeon_hole/typed_json.rb
|