escape_escape_escape 1.4.4 → 1.5.0

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: b50bc711e2b4881f6bfa26dc682430ec383b1448
4
- data.tar.gz: b5e154c1498090854e17779ffd3829cee2d78828
3
+ metadata.gz: 917266705f94b9a5286d0e59afcbb995d55714c3
4
+ data.tar.gz: e19d6689d8dbefae94448b59d86bc0d4e0231b57
5
5
  SHA512:
6
- metadata.gz: ab11e0dfcb60d639aeef4e6f4d3465e5a81ba5cfafa03b811a0fc911b0ae64d44f99c681fc47d61bef8020f506105d34694370b993ca682ec6e6647c8e716305
7
- data.tar.gz: 86816df90f646a7b3a55fcc282dde3d8180a42a33494f7d5feffd01a5b546f9014ce8c4b4d9314016fc0280b14c8837d3f8ecd3242cc22e085bafb04428b5676
6
+ metadata.gz: b902a308aca05401ed3794cec7ed6cb13f549babb5174056b802a98018806999333e4db1b0597c3e1335e4c46ab3543fed7b8b16add5514e2914e421d98ffb9c
7
+ data.tar.gz: 7812d9a8aac3446e92ef33803911bae0a63f85b16ed4d3767e36a13259bd79aa785af5e40434dd0f5e07dff59a12dbf97fdf87a2602661dd93f266507cf52b1a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.4
1
+ 1.5.0
@@ -299,10 +299,10 @@ class Escape_Escape_Escape
299
299
 
300
300
  def json_encode o
301
301
  case o
302
- when Array
303
- Oj.dump(o, mode: :strict)
302
+ when Hash
303
+ Oj.dump(clean_for_json(o), mode: :strict)
304
304
  else
305
- fail Invalid, "Not an Array: #{o.inspect}"
305
+ fail Invalid, "Not an object/hash: #{o.inspect}"
306
306
  end
307
307
  end
308
308
 
@@ -315,6 +315,25 @@ class Escape_Escape_Escape
315
315
  end
316
316
  end
317
317
 
318
+ private
319
+ def clean_for_json o
320
+ case o
321
+ when Hash
322
+ o.inject({}) { |memo, (k,v)|
323
+ memo[k.to_s] = clean_for_json(v)
324
+ memo
325
+ }
326
+ when Array
327
+ o.map { |v| clean_for_json v }
328
+ when Symbol
329
+ o.to_s
330
+ when String, Numeric, NilClass
331
+ o
332
+ else
333
+ fail ArgumentError, "Unknown Class for json: #{o.inspect}"
334
+ end
335
+ end
336
+
318
337
  end # === class self ===
319
338
 
320
339
  end # === class Escape_Escape_Escape ===
@@ -1,19 +1,24 @@
1
1
 
2
2
  it 'raises TypeError if it encounters an unallowed Object'
3
- input [Object.new]
4
- raises TypeError, /Failed to dump Object Object/
3
+ input( {'a'=>Object.new} )
4
+ raises ArgumentError, /Unknown Class for json:/
5
5
 
6
6
 
7
- it 'raises Invalid if not an Array:'
8
- input( {'a'=>'hello'} )
9
- raises Escape_Escape_Escape::Invalid, /Not an Array/
7
+ it 'raises Invalid if not a Hash:'
8
+ input( [{'a'=>'hello'}] )
9
+ raises Escape_Escape_Escape::Invalid, /Not an object\/hash/
10
10
 
11
11
 
12
- it 'raises Invalid if not an Array:'
12
+ it 'raises Invalid if not a Hash:'
13
13
  input 'a'
14
- raises Escape_Escape_Escape::Invalid, /Not an Array/
14
+ raises Escape_Escape_Escape::Invalid, /Not an object\/hash/
15
15
 
16
16
 
17
- it 'raises Invalid if not an Array:'
17
+ it 'raises Invalid if not an Hash:'
18
18
  input 1
19
- raises Escape_Escape_Escape::Invalid, /Not an Array: 1/
19
+ raises Escape_Escape_Escape::Invalid, /Not an object\/hash/
20
+
21
+
22
+ it 'turns Symbol keys and values into Strings'
23
+ input( {:a=>:c} )
24
+ output '{"a":"c"}'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: escape_escape_escape
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.4
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - da99
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-22 00:00:00.000000000 Z
11
+ date: 2015-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable