pigeon_hole 0.1.3 → 0.1.4
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/json_hash.rb +8 -4
- data/spec/integration_spec.rb +29 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5832510bdae9abe38905c94cafa44a3085266589
|
4
|
+
data.tar.gz: 99128a94f31c571c22bd6b4ec6e3c1b16e4012b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0413017c6b960c23db3390750c45a74a4e3a322ddb8c0b349894f33f10095f96ffad16cda9fc861eb8d24fddb654222506f2dc100f1397e5d3bf2a62862ade79
|
7
|
+
data.tar.gz: 2e6ef6ff33385381b51db529b41cea61a4a960137d120663aa78d205cf82f4135c79f56562e34b1d8e31d538e41e638bf1da16091ac4d89171008fd8d2ce2c93
|
@@ -3,10 +3,14 @@ module PigeonHole
|
|
3
3
|
TYPE_VALUE = 'hash'.freeze
|
4
4
|
|
5
5
|
def self.serialize(hash)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
if hash.empty?
|
7
|
+
{}
|
8
|
+
else
|
9
|
+
{
|
10
|
+
TypedJSON::TYPE_KEY => TYPE_VALUE,
|
11
|
+
'v' => hash.to_a
|
12
|
+
}
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
def self.deserialize(hash)
|
data/spec/integration_spec.rb
CHANGED
@@ -78,7 +78,8 @@ describe "serializing nested hashes" do
|
|
78
78
|
"foo" => {
|
79
79
|
"bar" => random_time,
|
80
80
|
"baz" => :temp,
|
81
|
-
}
|
81
|
+
},
|
82
|
+
"empty" => {}
|
82
83
|
}
|
83
84
|
end
|
84
85
|
|
@@ -132,6 +133,33 @@ describe "can deserialize standard json hashes" do
|
|
132
133
|
end
|
133
134
|
end
|
134
135
|
|
136
|
+
describe "can serialize an empty hash efficiently" do
|
137
|
+
let(:input) { Hash.new }
|
138
|
+
|
139
|
+
subject { PigeonHole.generate(input) }
|
140
|
+
|
141
|
+
it "serializes hash into a string" do
|
142
|
+
result = subject
|
143
|
+
expect(result).to_not be_empty
|
144
|
+
expect(result).to eq('{}')
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "can deserialize an empty hash" do
|
150
|
+
it "can be deserialized to a hash" do
|
151
|
+
hash = PigeonHole.parse('{}')
|
152
|
+
|
153
|
+
expect(hash).to eq({})
|
154
|
+
end
|
155
|
+
|
156
|
+
it "can deserialize legacy strings" do
|
157
|
+
hash = PigeonHole.parse('{"*": "hash", "v": []}')
|
158
|
+
|
159
|
+
expect(hash).to eq({})
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
135
163
|
describe "serializing custom type" do
|
136
164
|
CustomType = Struct.new(:name)
|
137
165
|
|
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.4
|
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-
|
11
|
+
date: 2016-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
44
|
version: '0'
|
45
45
|
requirements: []
|
46
46
|
rubyforge_project:
|
47
|
-
rubygems_version: 2.6.
|
47
|
+
rubygems_version: 2.6.7
|
48
48
|
signing_key:
|
49
49
|
specification_version: 4
|
50
50
|
summary: Opt-in typed serialization for complex JSON types
|