escape_escape_escape 1.4.4 → 1.5.0
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/VERSION +1 -1
- data/lib/escape_escape_escape.rb +22 -3
- data/specs/as_ruby/0051-json_encode.rb +14 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 917266705f94b9a5286d0e59afcbb995d55714c3
|
4
|
+
data.tar.gz: e19d6689d8dbefae94448b59d86bc0d4e0231b57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b902a308aca05401ed3794cec7ed6cb13f549babb5174056b802a98018806999333e4db1b0597c3e1335e4c46ab3543fed7b8b16add5514e2914e421d98ffb9c
|
7
|
+
data.tar.gz: 7812d9a8aac3446e92ef33803911bae0a63f85b16ed4d3767e36a13259bd79aa785af5e40434dd0f5e07dff59a12dbf97fdf87a2602661dd93f266507cf52b1a
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.5.0
|
data/lib/escape_escape_escape.rb
CHANGED
@@ -299,10 +299,10 @@ class Escape_Escape_Escape
|
|
299
299
|
|
300
300
|
def json_encode o
|
301
301
|
case o
|
302
|
-
when
|
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
|
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
|
4
|
-
raises
|
3
|
+
input( {'a'=>Object.new} )
|
4
|
+
raises ArgumentError, /Unknown Class for json:/
|
5
5
|
|
6
6
|
|
7
|
-
it 'raises Invalid if not
|
8
|
-
input( {'a'=>'hello'} )
|
9
|
-
raises Escape_Escape_Escape::Invalid, /Not an
|
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
|
12
|
+
it 'raises Invalid if not a Hash:'
|
13
13
|
input 'a'
|
14
|
-
raises Escape_Escape_Escape::Invalid, /Not an
|
14
|
+
raises Escape_Escape_Escape::Invalid, /Not an object\/hash/
|
15
15
|
|
16
16
|
|
17
|
-
it 'raises Invalid if not an
|
17
|
+
it 'raises Invalid if not an Hash:'
|
18
18
|
input 1
|
19
|
-
raises Escape_Escape_Escape::Invalid, /Not an
|
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
|
+
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-
|
11
|
+
date: 2015-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|