oj 3.4.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.4.0'
4
+ VERSION = '3.5.0'
5
5
  end
@@ -10,7 +10,7 @@ in a JSON document. The formatting follows these rules.
10
10
  * JSON native types, true, false, nil, String, Hash, Array, and Number are
11
11
  encoded normally.
12
12
 
13
- * A Symbol is encoded as a JSON string with a preceeding `':'` character.
13
+ * A Symbol is encoded as a JSON string with a preceding `':'` character.
14
14
 
15
15
  * The `'^'` character denotes a special key value when in a JSON Object sequence.
16
16
 
@@ -28,7 +28,7 @@ in a JSON document. The formatting follows these rules.
28
28
  * A `"^o"` JSON Object key indicates the value should be converted to a Ruby
29
29
  Object. The first entry in the JSON Object must be a class with the `"^o"`
30
30
  key. After that each entry is treated as a variable of the Object where the
31
- key is the variable name without the preceeding `'@'`. An example is
31
+ key is the variable name without the preceding `'@'`. An example is
32
32
  `{"^o":"Oj::Bag","x":58,"y":"marbles"}`. `"^O"`is the same except that it
33
33
  is for built in or odd classes that don't obey the normal Ruby
34
34
  rules. Examples are Rational, Date, and DateTime.
@@ -40,7 +40,7 @@ in a JSON document. The formatting follows these rules.
40
40
  `{"^u":["Range",1,7,false]}`.
41
41
 
42
42
  * When encoding an Object, if the variable name does not begin with an
43
- `'@'`character then the name preceeded by a `'~'` character. This occurs in
43
+ `'@'`character then the name preceded by a `'~'` character. This occurs in
44
44
  the Exception class. An example is `{"^o":"StandardError","~mesg":"A
45
45
  Message","~bt":[".\/tests.rb:345:in 'test_exception'"]}`.
46
46
 
@@ -120,6 +120,7 @@ information.
120
120
  | :space | String | | | x | x | | x | |
121
121
  | :space_before | String | | | x | x | | x | |
122
122
  | :symbol_keys | Boolean | x | x | x | x | x | x | |
123
+ | :trace | Boolean | x | x | x | x | x | x | x |
123
124
  | :time_format | Symbol | | | | | x | x | |
124
125
  | :use_as_json | Boolean | | | | | | x | |
125
126
  | :use_to_hash | Boolean | | | | | | x | |
@@ -80,7 +80,7 @@ dynamically modifying classes or reloading classes then don't use this.
80
80
 
81
81
  ### :create_additions
82
82
 
83
- A flag indicating the :create_id key when encounterd during parsing should
83
+ A flag indicating the :create_id key when encountered during parsing should
84
84
  creating an Object mactching the class name specified in the value associated
85
85
  with the key.
86
86
 
@@ -226,6 +226,11 @@ compatibility. Using just indent as an integer gives better performance.
226
226
 
227
227
  Use symbols instead of strings for hash keys. :symbolize_names is an alias.
228
228
 
229
+ ### :trace
230
+
231
+ When true dump and load functions are traced by printing beginning and ending
232
+ of blocks and of specific calls.
233
+
229
234
  ### :time_format [Symbol]
230
235
 
231
236
  The :time_format when dumping.
@@ -20,6 +20,11 @@ or simply call
20
20
  Oj.optimize_rails()
21
21
  ```
22
22
 
23
+ Either of those steps will setup Oj to mimic Rails but it will not change the
24
+ default mode type as the mode type is only used when calling the Oj encoding
25
+ directly. If Rails mode is also desired then use the `Oj.default_options` to
26
+ change the default mode.
27
+
23
28
  Some of the Oj options are supported as arguments to the encoder if called
24
29
  from Oj::Rails.encode() but when using the Oj::Rails::Encoder class the
25
30
  encode() method does not support optional arguments as required by the
@@ -73,7 +78,7 @@ Oj::Rails.optimize is called with no arguments are:
73
78
  * any other class where all attributes should be dumped
74
79
 
75
80
  The ActiveSupport decoder is the JSON.parse() method. Calling the
76
- Oj::Rails.set_decoder() method replaces that method with the Oj equivelant.
81
+ Oj::Rails.set_decoder() method replaces that method with the Oj equivalent.
77
82
 
78
83
  ### Notes:
79
84
 
@@ -88,6 +93,24 @@ Oj::Rails.set_decoder() method replaces that method with the Oj equivelant.
88
93
  are used as keys or if a other non-String objects such as Numerics are mixed
89
94
  with numbers as Strings.
90
95
 
91
- 3. To verify Oj is being used turn on trace and then set the
92
- `Tracer.display_c_call = true` to see calls to C extensions.
93
-
96
+ 3. To verify Oj is being used turn on the Oj `:trace` option. Similar to the
97
+ Ruby Tracer Oj will then print out trace information. Another approach is
98
+ to turn on C extension tracing. Set `tracer = TracePoint.new(:c_call) do
99
+ |tp| p [tp.lineno, tp.event, tp.defined_class, tp.method_id] end` or, in
100
+ older Rubies, set `Tracer.display_c_call = true`.
101
+
102
+ For example:
103
+
104
+ ```
105
+ require 'active_support/core_ext'
106
+ require 'active_support/json'
107
+ require 'oj'
108
+ Oj.optimize_rails
109
+ tracer.enable { Time.now.to_json }
110
+ # prints output including
111
+ ....
112
+ [20, :c_call, #<Class:Oj::Rails::Encoder>, :new]
113
+ [20, :c_call, Oj::Rails::Encoder, :encode]
114
+ ....
115
+ => "\"2018-02-23T12:13:42.493-06:00\""
116
+ ```
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require 'activesupport5/test_helper'
2
3
  require 'securerandom'
3
4
  require 'active_support/core_ext/string/inflections'
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << '.'
4
+ $: << '../lib'
5
+ $: << '../ext'
6
+
7
+ require 'oj'
8
+ require 'sample'
9
+
10
+ #obj = sample_doc(1)
11
+
12
+ class Foo
13
+ def initialize()
14
+ @x = 'abc'
15
+ @y = 123
16
+ @a = [{}]
17
+ end
18
+ end
19
+
20
+ obj = Foo.new
21
+ obj = {
22
+ x: 'abc',
23
+ y: 123,
24
+ a: [{}]
25
+ }
26
+
27
+ j = Oj.dump(obj, mode: :rails, trace: true)
28
+ #j = Oj.dump(obj, mode: :compat)
29
+
30
+ puts j
31
+
32
+ Oj.load(j, mode: :rails, trace: true)
@@ -155,6 +155,7 @@ class Juice < Minitest::Test
155
155
  :allow_nan=>true,
156
156
  :array_class=>Array,
157
157
  :ignore=>nil,
158
+ :trace=>true,
158
159
  }
159
160
  Oj.default_options = alt
160
161
  #keys = alt.keys
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: 3.4.0
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-24 00:00:00.000000000 Z
11
+ date: 2018-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -137,6 +137,8 @@ files:
137
137
  - ext/oj/stream_writer.c
138
138
  - ext/oj/strict.c
139
139
  - ext/oj/string_writer.c
140
+ - ext/oj/trace.c
141
+ - ext/oj/trace.h
140
142
  - ext/oj/val_stack.c
141
143
  - ext/oj/val_stack.h
142
144
  - ext/oj/wab.c
@@ -173,6 +175,7 @@ files:
173
175
  - test/activesupport5/test_helper.rb
174
176
  - test/activesupport5/time_zone_test_helpers.rb
175
177
  - test/files.rb
178
+ - test/foo.rb
176
179
  - test/helper.rb
177
180
  - test/isolated/shared.rb
178
181
  - test/isolated/test_mimic_after.rb
@@ -238,7 +241,13 @@ files:
238
241
  homepage: http://www.ohler.com/oj
239
242
  licenses:
240
243
  - MIT
241
- metadata: {}
244
+ metadata:
245
+ bug_tracker_uri: https://github.com/ohler55/oj/issues
246
+ changelog_uri: https://github.com/ohler55/oj/blob/master/CHANGELOG.md
247
+ documentation_uri: http://www.ohler.com/oj/doc/index.html
248
+ homepage_uri: http://www.ohler.com/oj/
249
+ source_code_uri: https://github.com/ohler55/oj
250
+ wiki_uri: https://github.com/ohler55/oj/wiki
242
251
  post_install_message:
243
252
  rdoc_options:
244
253
  - "--title"
@@ -258,8 +267,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
267
  - !ruby/object:Gem::Version
259
268
  version: '0'
260
269
  requirements: []
261
- rubyforge_project: oj
262
- rubygems_version: 2.6.11
270
+ rubyforge_project:
271
+ rubygems_version: 2.7.3
263
272
  signing_key:
264
273
  specification_version: 4
265
274
  summary: A fast JSON parser and serializer.
@@ -321,6 +330,7 @@ test_files:
321
330
  - test/activesupport4/encoding_test.rb
322
331
  - test/test_wab.rb
323
332
  - test/perf_file.rb
333
+ - test/foo.rb
324
334
  - test/perf_compat.rb
325
335
  - test/test_various.rb
326
336
  - test/test_strict.rb