Module: ActiveSupport::JSON
- Defined in:
- activesupport/lib/active_support/json/variable.rb,
activesupport/lib/active_support/json/decoding.rb,
activesupport/lib/active_support/json/encoding.rb,
activesupport/lib/active_support/json/backends/yaml.rb,
activesupport/lib/active_support/json/backends/yajl.rb,
activesupport/lib/active_support/json/backends/jsongem.rb
Defined Under Namespace
Modules: Backends, Encoding Classes: Variable
Constant Summary
- DECODERS =
Listed in order of preference.
%w(Yajl
- 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)
-
+ (Object) parse_error
readonly
Returns the value of attribute parse_error.
Class Method Summary (collapse)
- + (Object) backend
- + (Object) backend=(name)
-
+ (Object) encode(value, options = nil)
Dumps object in JSON (JavaScript Object Notation).
- + (Object) set_default_backend
- + (Object) with_backend(name)
Class Attribute Details
+ (Object) parse_error (readonly)
Returns the value of attribute parse_error
13 14 15 |
# File 'activesupport/lib/active_support/json/decoding.rb', line 13 def parse_error @parse_error end |
Class Method Details
+ (Object) backend
16 17 18 19 |
# File 'activesupport/lib/active_support/json/decoding.rb', line 16 def backend set_default_backend unless defined?(@backend) @backend end |
+ (Object) backend=(name)
21 22 23 24 25 26 27 28 29 |
# File 'activesupport/lib/active_support/json/decoding.rb', line 21 def backend=(name) if name.is_a?(Module) @backend = name else require "active_support/json/backends/#{name.to_s.downcase}" @backend = ActiveSupport::JSON::Backends::const_get(name) end @parse_error = @backend::ParseError end |
+ (Object) encode(value, options = nil)
Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info.
29 30 31 |
# File 'activesupport/lib/active_support/json/encoding.rb', line 29 def self.encode(value, = nil) Encoding::Encoder.new().encode(value) end |
+ (Object) set_default_backend
38 39 40 41 42 43 44 45 46 47 48 |
# File 'activesupport/lib/active_support/json/decoding.rb', line 38 def set_default_backend DECODERS.find do |name| begin self.backend = name true rescue LoadError # Try next decoder. false end end end |
+ (Object) with_backend(name)
31 32 33 34 35 36 |
# File 'activesupport/lib/active_support/json/decoding.rb', line 31 def with_backend(name) old_backend, self.backend = backend, name yield ensure self.backend = old_backend end |