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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9691f8acb8219c2c3ae074a50330d70dd16aa570
4
- data.tar.gz: 5a2056392495edcfc40e09833ee5880a91967f6f
3
+ metadata.gz: f73b57b7f55339462a957b6c76ab971c88e7dff4
4
+ data.tar.gz: 847e31692753ec27162889aa6b6d291b1271e0ce
5
5
  SHA512:
6
- metadata.gz: a469edf7288347abb45b33982da7b4e2985902212ff69d449397e9c0cc5d5f7b95a74b98bddba76c301714c55cca2ae9f8c5e41dfef9b4cfa142adf903120c0e
7
- data.tar.gz: 8501d3e3829b0438f7b2fc8837a9c3b839804ba29333ecac0ad4fd9ebb067d497ee8af668230c0fd8db845b1ab1ffbebda6df295312466317c3cf4efd564030f
6
+ metadata.gz: 086df0f1ea603ff6ceb99427091e00833a44677fac610fb334c60c24749c9619c9ae9bc81a1cd0758a8a082b1bf13d4703133fd4740d102f9282640ace9b57b8
7
+ data.tar.gz: 3a03198c64f3c6d2b243fe1bb056f0a30295485025bd88463515e588839496f8f92b2facb2f20f553b2d4a9628d203a16107c4305aac73de24a5cd502e780a72
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- n# JSONArraySerializer
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
@@ -0,0 +1,11 @@
1
+ # Extend OpenStruct to add #stringify_values.
2
+ class OpenStruct
3
+
4
+ # -> OpenStruct
5
+ # Returns a new OpenStruct where symbol values are converted
6
+ # into strings.
7
+ #
8
+ def stringify_values
9
+ OpenStruct.new(marshal_dump.stringify)
10
+ end
11
+ end
@@ -1,7 +1,7 @@
1
1
  require 'json'
2
2
  require 'json_array_serializer/version'
3
3
 
4
- class JSONArraySerializer
4
+ class JSONArraySerializer < Array
5
5
  attr_accessor :element_class
6
6
 
7
7
  # Class -> void (hook)
@@ -1,3 +1,3 @@
1
- class JSONArraySerializer
2
- VERSION = "0.0.1"
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
- class Hash
6
- def stringify
7
- inject({}) do |acc, (key, value)|
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.1
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-25 00:00:00.000000000 Z
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