Module: ActiveSupport
Overview
The JSON gem adds a few modules to Ruby core classes containing :to_json
definition, overwriting their default behavior. That said, we need to define the basic to_json method in all of them, otherwise they will always use to_json gem implementation, which is backwards incompatible in several cases (for instance, the JSON
implementation for ::Hash
does not work) with inheritance and consequently classes as OrderedHash
cannot be serialized to json.
On the other hand, we should avoid conflict with ::JSON
.generate,dump
(obj). Unfortunately, the JSON
gem’s encoder relies on its own to_json implementation to encode objects. Since it always passes a ::JSON::State object as the only argument to to_json, we can detect that and forward the calls to the original to_json method.
It should be noted that when using ::JSON
.generate,dump
directly, ActiveSupport’s encoder is bypassed completely. This means that as_json won’t be invoked and the JSON
gem will simply ignore any options it does not natively understand. This also means that ::JSON
.generate,dump
should give exactly the same results with or without active support.
Class Attribute Summary
-
.parse_json_times
(also: #parse_json_times)
rw
Look for and parse json strings that look like ISO 8601 times.
Class Method Summary
- .eager_load!
-
.gem_version
Returns the version of the currently loaded Active Support as a
Gem::Version
. -
.version
Returns the version of the currently loaded
ActiveSupport
as aGem::Version
LazyLoadHooks
- Extended
on_load | Declares a block that will be executed when a |
run_load_hooks |
Autoload
- Extended
Instance Attribute Summary
Class Attribute Details
.parse_json_times (rw) Also known as: #parse_json_times
Look for and parse json strings that look like ISO 8601 times.
# File 'activesupport/lib/active_support/json/decoding.rb', line 9
mattr_accessor :parse_json_times
Class Method Details
.eager_load!
[ GitHub ]# File 'activesupport/lib/active_support.rb', line 78
def self.eager_load! super NumberHelper.eager_load! end
.gem_version
Returns the version of the currently loaded Active Support as a Gem::Version
.
.version
Returns the version of the currently loaded ActiveSupport
as a Gem::Version
# File 'activesupport/lib/active_support/version.rb', line 7
def self.version gem_version end
Instance Attribute Details
#escape_html_entities_in_json (rw)
[ GitHub ]# File 'activesupport/lib/active_support/json/encoding.rb', line 8
delegate :use_standard_json_time_format, :use_standard_json_time_format=, :time_precision, :time_precision=, :escape_html_entities_in_json, :escape_html_entities_in_json=, :json_encoder, :json_encoder=, to: :'ActiveSupport::JSON::Encoding'
#json_encoder (rw)
[ GitHub ]# File 'activesupport/lib/active_support/json/encoding.rb', line 8
delegate :use_standard_json_time_format, :use_standard_json_time_format=, :time_precision, :time_precision=, :escape_html_entities_in_json, :escape_html_entities_in_json=, :json_encoder, :json_encoder=, to: :'ActiveSupport::JSON::Encoding'
#parse_json_times (rw)
[ GitHub ]# File 'activesupport/lib/active_support/json/decoding.rb', line 9
mattr_accessor :parse_json_times
#time_precision (rw)
[ GitHub ]# File 'activesupport/lib/active_support/json/encoding.rb', line 8
delegate :use_standard_json_time_format, :use_standard_json_time_format=, :time_precision, :time_precision=, :escape_html_entities_in_json, :escape_html_entities_in_json=, :json_encoder, :json_encoder=, to: :'ActiveSupport::JSON::Encoding'
#use_standard_json_time_format (rw)
[ GitHub ]# File 'activesupport/lib/active_support/json/encoding.rb', line 8
delegate :use_standard_json_time_format, :use_standard_json_time_format=, :time_precision, :time_precision=, :escape_html_entities_in_json, :escape_html_entities_in_json=, :json_encoder, :json_encoder=, to: :'ActiveSupport::JSON::Encoding'