json_array_serializer 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/ext/hash.rb +21 -0
- data/ext/open_struct.rb +11 -0
- data/lib/json_array_serializer.rb +1 -1
- data/lib/json_array_serializer/version.rb +2 -2
- data/spec/json_array_serializer_spec.rb +5 -0
- data/spec/spec_helper.rb +3 -21
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f73b57b7f55339462a957b6c76ab971c88e7dff4
|
4
|
+
data.tar.gz: 847e31692753ec27162889aa6b6d291b1271e0ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 086df0f1ea603ff6ceb99427091e00833a44677fac610fb334c60c24749c9619c9ae9bc81a1cd0758a8a082b1bf13d4703133fd4740d102f9282640ace9b57b8
|
7
|
+
data.tar.gz: 3a03198c64f3c6d2b243fe1bb056f0a30295485025bd88463515e588839496f8f92b2facb2f20f553b2d4a9628d203a16107c4305aac73de24a5cd502e780a72
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# JSONArraySerializer
|
2
2
|
|
3
3
|
A class to serialize and deserialize arrays of JSON strings. This is useful when doing things like saving arrays of objects to a database or file, or sending them over the wire.
|
4
4
|
|
@@ -60,4 +60,4 @@ The class you pass to `JSONArraySerializer.new` __must__ have the following two
|
|
60
60
|
```
|
61
61
|
# A.new : Hash -> A
|
62
62
|
# a.to_h : -> Hash (where a is an instance of A)
|
63
|
-
```
|
63
|
+
```
|
data/ext/hash.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Extend the Hash class to add #stringify.
|
2
|
+
class Hash
|
3
|
+
|
4
|
+
# -> Hash
|
5
|
+
# Returns a new hash with all of the symbols inside
|
6
|
+
# converted into strings recursively.
|
7
|
+
#
|
8
|
+
def stringify
|
9
|
+
inject({}) do |acc, (key, value)|
|
10
|
+
acc[key.to_s] = case value
|
11
|
+
when Symbol
|
12
|
+
value.to_s
|
13
|
+
when Hash
|
14
|
+
value.stringify
|
15
|
+
else
|
16
|
+
value
|
17
|
+
end
|
18
|
+
acc
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/ext/open_struct.rb
ADDED
@@ -1,3 +1,3 @@
|
|
1
|
-
class JSONArraySerializer
|
2
|
-
VERSION = "0.0.
|
1
|
+
class JSONArraySerializer < Array
|
2
|
+
VERSION = "0.0.2"
|
3
3
|
end
|
@@ -2,6 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe JSONArraySerializer do
|
4
4
|
|
5
|
+
it 'is an array' do
|
6
|
+
serializer = JSONArraySerializer.new
|
7
|
+
expect(serializer).to be_an(Array)
|
8
|
+
end
|
9
|
+
|
5
10
|
context 'text backed serialization' do
|
6
11
|
context 'default class (Hash)' do
|
7
12
|
let(:serializer) { JSONArraySerializer.new }
|
data/spec/spec_helper.rb
CHANGED
@@ -2,27 +2,9 @@ require 'rspec'
|
|
2
2
|
require 'ostruct'
|
3
3
|
require 'json_array_serializer'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
acc[key.to_s] = case value
|
9
|
-
when Symbol
|
10
|
-
value.to_s
|
11
|
-
when Hash
|
12
|
-
value.stringify
|
13
|
-
else
|
14
|
-
value
|
15
|
-
end
|
16
|
-
acc
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class OpenStruct
|
22
|
-
def stringify_values
|
23
|
-
OpenStruct.new(marshal_dump.stringify)
|
24
|
-
end
|
25
|
-
end
|
5
|
+
# Connivance extensions.
|
6
|
+
require_relative '../ext/hash'
|
7
|
+
require_relative '../ext/open_struct'
|
26
8
|
|
27
9
|
RSpec.configure do |config|
|
28
10
|
config.color_enabled = true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_array_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Lilienthal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -65,6 +65,8 @@ files:
|
|
65
65
|
- LICENSE.txt
|
66
66
|
- README.md
|
67
67
|
- Rakefile
|
68
|
+
- ext/hash.rb
|
69
|
+
- ext/open_struct.rb
|
68
70
|
- json_array_serializer.gemspec
|
69
71
|
- lib/json_array_serializer.rb
|
70
72
|
- lib/json_array_serializer/version.rb
|