pages/Rails.md in oj-3.4.0 vs pages/Rails.md in oj-3.5.0
- old
+ new
@@ -18,10 +18,15 @@
```ruby
Oj.optimize_rails()
```
+Either of those steps will setup Oj to mimic Rails but it will not change the
+default mode type as the mode type is only used when calling the Oj encoding
+directly. If Rails mode is also desired then use the `Oj.default_options` to
+change the default mode.
+
Some of the Oj options are supported as arguments to the encoder if called
from Oj::Rails.encode() but when using the Oj::Rails::Encoder class the
encode() method does not support optional arguments as required by the
ActiveSupport compliance guidelines. The general approach Rails takes for
configuring encoding options is to either set global values or to create a new
@@ -71,11 +76,11 @@
* ActionController::Parameters
* any class inheriting from ActiveRecord::Base
* any other class where all attributes should be dumped
The ActiveSupport decoder is the JSON.parse() method. Calling the
-Oj::Rails.set_decoder() method replaces that method with the Oj equivelant.
+Oj::Rails.set_decoder() method replaces that method with the Oj equivalent.
### Notes:
1. Optimized Floats set the significant digits to 16. This is different than
Ruby which is used by the json gem and by Rails. Ruby varies the
@@ -86,8 +91,26 @@
return value of the to_s() method in the output without checking to see if
that has already been used. This could occur is a mix of String and Symbols
are used as keys or if a other non-String objects such as Numerics are mixed
with numbers as Strings.
-3. To verify Oj is being used turn on trace and then set the
- `Tracer.display_c_call = true` to see calls to C extensions.
-
\ No newline at end of file
+3. To verify Oj is being used turn on the Oj `:trace` option. Similar to the
+ Ruby Tracer Oj will then print out trace information. Another approach is
+ to turn on C extension tracing. Set `tracer = TracePoint.new(:c_call) do
+ |tp| p [tp.lineno, tp.event, tp.defined_class, tp.method_id] end` or, in
+ older Rubies, set `Tracer.display_c_call = true`.
+
+ For example:
+
+ ```
+ require 'active_support/core_ext'
+ require 'active_support/json'
+ require 'oj'
+ Oj.optimize_rails
+ tracer.enable { Time.now.to_json }
+ # prints output including
+ ....
+ [20, :c_call, #<Class:Oj::Rails::Encoder>, :new]
+ [20, :c_call, Oj::Rails::Encoder, :encode]
+ ....
+ => "\"2018-02-23T12:13:42.493-06:00\""
+ ```