oj 2.1.3 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of oj might be problematic. Click here for more details.

Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -4
  3. data/ext/oj/compat.c +3 -4
  4. data/ext/oj/encode.h +51 -0
  5. data/ext/oj/fast.c +4 -9
  6. data/ext/oj/object.c +7 -19
  7. data/ext/oj/oj.c +32 -12
  8. data/ext/oj/oj.h +3 -0
  9. data/ext/oj/parse.c +2 -3
  10. data/ext/oj/saj.c +4 -9
  11. data/ext/oj/scp.c +5 -12
  12. data/ext/oj/strict.c +5 -12
  13. data/lib/oj/version.rb +1 -1
  14. data/test/a.rb +38 -0
  15. data/test/bug.rb +15 -0
  16. data/test/e.rb +12 -0
  17. data/test/files.rb +29 -0
  18. data/test/foo.rb +24 -0
  19. data/test/mj.rb +48 -0
  20. data/test/perf.rb +107 -0
  21. data/test/perf_compat.rb +128 -0
  22. data/test/perf_fast.rb +164 -0
  23. data/test/perf_object.rb +136 -0
  24. data/test/perf_saj.rb +109 -0
  25. data/test/perf_scp.rb +151 -0
  26. data/test/perf_simple.rb +287 -0
  27. data/test/perf_strict.rb +127 -0
  28. data/test/sample.rb +55 -0
  29. data/test/sample/change.rb +14 -0
  30. data/test/sample/dir.rb +19 -0
  31. data/test/sample/doc.rb +36 -0
  32. data/test/sample/file.rb +48 -0
  33. data/test/sample/group.rb +16 -0
  34. data/test/sample/hasprops.rb +16 -0
  35. data/test/sample/layer.rb +12 -0
  36. data/test/sample/line.rb +20 -0
  37. data/test/sample/oval.rb +10 -0
  38. data/test/sample/rect.rb +10 -0
  39. data/test/sample/shape.rb +35 -0
  40. data/test/sample/text.rb +20 -0
  41. data/test/sample_json.rb +37 -0
  42. data/test/test_compat.rb +342 -0
  43. data/test/test_fast.rb +416 -0
  44. data/test/test_mimic.rb +208 -0
  45. data/test/test_mimic_after.rb +35 -0
  46. data/test/test_object.rb +390 -0
  47. data/test/test_saj.rb +184 -0
  48. data/test/test_scp.rb +224 -0
  49. data/test/test_strict.rb +259 -0
  50. data/test/tests.rb +1017 -0
  51. data/test/x.rb +59 -0
  52. metadata +41 -2
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
5
+ # required. That can be set in the RUBYOPT environment variable.
6
+ # export RUBYOPT=-w
7
+
8
+ $VERBOSE = true
9
+
10
+ $: << File.join(File.dirname(__FILE__), "../lib")
11
+ $: << File.join(File.dirname(__FILE__), "../ext")
12
+
13
+ require 'oj'
14
+
15
+ # Oj is not able to deserialize all classes that are a subclass of a Ruby
16
+ # Exception. Only exception that take one required string argument in the
17
+ # initialize() method are supported. This is an example of how to write an
18
+ # Exception subclass that supports both a single string intializer and an
19
+ # Exception as an argument. Additional optional arguments can be added as well.
20
+ #
21
+ # The reason for this restriction has to do with a design decision on the part
22
+ # of the Ruby developers. Exceptions are special Objects. They do not follow the
23
+ # rules of other Objects. Exceptions have 'mesg' and a 'bt' attribute. Note that
24
+ # these are not '@mesg' and '@bt'. They can not be set using the normal C or
25
+ # Ruby calls. The only way I have found to set the 'mesg' attribute is through
26
+ # the initializer. Unfortunately that means any subclass that provides a
27
+ # different initializer can not be automatically decoded. A way around this is
28
+ # to use a create function but this example shows an alternative.
29
+
30
+ class WrapException < StandardError
31
+ attr_reader :original
32
+
33
+ def initialize(msg_or_err)
34
+ if msg_or_err.is_a?(Exception)
35
+ super(msg_or_err.message)
36
+ @original = msg_or_err
37
+ set_backtrace(msg_or_err.backtrace)
38
+ else
39
+ super(message)
40
+ @original = nil
41
+ end
42
+ end
43
+ end
44
+
45
+ e = WrapException.new(RuntimeError.new("Something broke."))
46
+
47
+ json = Oj.dump(e, :mode => :object)
48
+ puts "original:\n#{json}"
49
+ # outputs:
50
+ # original:
51
+ # {"^o":"WrapException","original":{"^o":"RuntimeError","~mesg":"Something broke.","~bt":null},"~mesg":"Something broke.","~bt":null}
52
+
53
+ e2 = Oj.load(json, :mode => :object)
54
+ puts "dumped, loaded, and dumped again:\n#{Oj.dump(e2, :mode => :object)}"
55
+ # outputs:
56
+ # original: {"^o":"WrapException","original":{"^o":"RuntimeError","~mesg":"Something broke.","~bt":null},"~mesg":"Something broke.","~bt":null}
57
+ # dumped, loaded, and dumped again:
58
+ # {"^o":"WrapException","original":{"^o":"RuntimeError","~mesg":"Something broke.","~bt":null},"~mesg":"Something broke.","~bt":null}
59
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-30 00:00:00.000000000 Z
11
+ date: 2013-07-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'The fastest JSON parser and object serializer. '
14
14
  email: peter@ohler.com
@@ -29,6 +29,7 @@ files:
29
29
  - ext/oj/buf.h
30
30
  - ext/oj/cache8.h
31
31
  - ext/oj/circarray.h
32
+ - ext/oj/encode.h
32
33
  - ext/oj/err.h
33
34
  - ext/oj/hash.h
34
35
  - ext/oj/odd.h
@@ -53,6 +54,44 @@ files:
53
54
  - ext/oj/scp.c
54
55
  - ext/oj/strict.c
55
56
  - ext/oj/val_stack.c
57
+ - test/a.rb
58
+ - test/bug.rb
59
+ - test/e.rb
60
+ - test/files.rb
61
+ - test/foo.rb
62
+ - test/mj.rb
63
+ - test/perf.rb
64
+ - test/perf_compat.rb
65
+ - test/perf_fast.rb
66
+ - test/perf_object.rb
67
+ - test/perf_saj.rb
68
+ - test/perf_scp.rb
69
+ - test/perf_simple.rb
70
+ - test/perf_strict.rb
71
+ - test/sample/change.rb
72
+ - test/sample/dir.rb
73
+ - test/sample/doc.rb
74
+ - test/sample/file.rb
75
+ - test/sample/group.rb
76
+ - test/sample/hasprops.rb
77
+ - test/sample/layer.rb
78
+ - test/sample/line.rb
79
+ - test/sample/oval.rb
80
+ - test/sample/rect.rb
81
+ - test/sample/shape.rb
82
+ - test/sample/text.rb
83
+ - test/sample.rb
84
+ - test/sample_json.rb
85
+ - test/test_compat.rb
86
+ - test/test_fast.rb
87
+ - test/test_mimic.rb
88
+ - test/test_mimic_after.rb
89
+ - test/test_object.rb
90
+ - test/test_saj.rb
91
+ - test/test_scp.rb
92
+ - test/test_strict.rb
93
+ - test/tests.rb
94
+ - test/x.rb
56
95
  - LICENSE
57
96
  - README.md
58
97
  homepage: http://www.ohler.com/oj