Class Index [+]

Quicksearch

ActiveSupport::JSON

Constants

DATE_REGEX

matches YAML-formatted dates

Public Class Methods

decode(json, options ={}) click to toggle source
    # File lib/active_support/json/decoding.rb, line 11
11:       def decode(json, options ={})
12:         # Can't reliably detect whether MultiJson responds to load, since it's
13:         # a reserved word. Use adapter as a proxy for new features.
14:         data = if MultiJson.respond_to?(:adapter)
15:           MultiJson.load(json, options)
16:         else
17:           MultiJson.decode(json, options)
18:         end
19:         if ActiveSupport.parse_json_times
20:           convert_dates_from(data)
21:         else
22:           data
23:         end
24:       end
encode(value, options = nil) click to toggle source

Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info.

    # File lib/active_support/json/encoding.rb, line 30
30:     def self.encode(value, options = nil)
31:       Encoding::Encoder.new(options).encode(value)
32:     end
engine() click to toggle source
    # File lib/active_support/json/decoding.rb, line 26
26:       def engine
27:         if MultiJson.respond_to?(:adapter)
28:           MultiJson.adapter
29:         else
30:           MultiJson.engine
31:         end
32:       end
engine=(name) click to toggle source
    # File lib/active_support/json/decoding.rb, line 35
35:       def engine=(name)
36:         if MultiJson.respond_to?(:use)
37:           MultiJson.use name
38:         else
39:           MultiJson.engine = name
40:         end
41:       end
parse_error() click to toggle source
    # File lib/active_support/json/decoding.rb, line 51
51:       def parse_error
52:         MultiJson::DecodeError
53:       end
with_backend(name) click to toggle source
    # File lib/active_support/json/decoding.rb, line 44
44:       def with_backend(name)
45:         old_backend, self.backend = backend, name
46:         yield
47:       ensure
48:         self.backend = old_backend
49:       end

Private Class Methods

convert_dates_from(data) click to toggle source
    # File lib/active_support/json/decoding.rb, line 57
57:       def convert_dates_from(data)
58:         case data
59:         when nil
60:           nil
61:         when DATE_REGEX
62:           begin
63:             DateTime.parse(data)
64:           rescue ArgumentError
65:             data
66:           end
67:         when Array
68:           data.map! { |d| convert_dates_from(d) }
69:         when Hash
70:           data.each do |key, value|
71:             data[key] = convert_dates_from(value)
72:           end
73:         else
74:           data
75:         end
76:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.