Module: ActiveSupport::JSON
- Defined in:
- lib/active_support/json/decoding.rb,
lib/active_support/json/encoding.rb,
lib/active_support/json/variable.rb,
lib/active_support/json/backends/yajl.rb,
lib/active_support/json/backends/yaml.rb,
lib/active_support/json/backends/okjson.rb,
lib/active_support/json/backends/jsongem.rb
Defined Under Namespace
Modules: Backends, Encoding Classes: Variable
Constant Summary collapse
- DECODERS =
Listed in order of preference.
%w(Yajl OkJson)
- DATE_REGEX =
matches YAML-formatted dates
/^(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}[ \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?))$/
- CircularReferenceError =
Deprecation::DeprecatedConstantProxy.new('ActiveSupport::JSON::CircularReferenceError', Encoding::CircularReferenceError)
Class Attribute Summary collapse
-
.parse_error ⇒ Object
readonly
Returns the value of attribute parse_error.
Class Method Summary collapse
- .backend ⇒ Object
- .backend=(name) ⇒ Object
- .set_default_backend ⇒ Object
- .with_backend(name) ⇒ Object
Class Attribute Details
.parse_error ⇒ Object (readonly)
Returns the value of attribute parse_error.
12 13 14 |
# File 'lib/active_support/json/decoding.rb', line 12 def parse_error @parse_error end |
Class Method Details
.backend ⇒ Object
15 16 17 18 |
# File 'lib/active_support/json/decoding.rb', line 15 def backend set_default_backend unless defined?(@backend) @backend end |
.backend=(name) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/active_support/json/decoding.rb', line 20 def backend=(name) if name.is_a?(Module) @backend = name else require "active_support/json/backends/#{name.to_s.downcase}.rb" @backend = ActiveSupport::JSON::Backends::const_get(name) end @parse_error = @backend::ParseError end |
.set_default_backend ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/active_support/json/decoding.rb', line 37 def set_default_backend DECODERS.find do |name| begin self.backend = name true rescue LoadError # Try next decoder. false end end end |
.with_backend(name) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/active_support/json/decoding.rb', line 30 def with_backend(name) old_backend, self.backend = backend, name yield ensure self.backend = old_backend end |