aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-09-14 22:47:21 -0500
committerFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-09-14 22:47:21 -0500
commit7ef21d80a3b58e5dc5a1e2c83e95ae0a34b786e0 (patch)
tree3efa785e3dec7ece79e51093b2f0d75a18c097b6 /activesupport
parent5ea3f284a4d07f5572f7ae2a7442cca8761fa8fc (diff)
downloadrails-7ef21d80a3b58e5dc5a1e2c83e95ae0a34b786e0.tar.gz
rails-7ef21d80a3b58e5dc5a1e2c83e95ae0a34b786e0.tar.bz2
rails-7ef21d80a3b58e5dc5a1e2c83e95ae0a34b786e0.zip
update AS/json docs [ci skip]
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/json/decoding.rb6
-rw-r--r--activesupport/lib/active_support/json/encoding.rb26
2 files changed, 20 insertions, 12 deletions
diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb
index e44939e78a..a4a32b2ad0 100644
--- a/activesupport/lib/active_support/json/decoding.rb
+++ b/activesupport/lib/active_support/json/decoding.rb
@@ -39,8 +39,10 @@ module ActiveSupport
self.backend = old_backend
end
- # Returns the class of the error that will be raised when there is an error in decoding JSON.
- # Using this method means you won't directly depend on the ActiveSupport's JSON implementation, in case it changes in the future.
+ # Returns the class of the error that will be raised when there is an
+ # error in decoding JSON. Using this method means you won't directly
+ # depend on the ActiveSupport's JSON implementation, in case it changes
+ # in the future.
#
# begin
# obj = ActiveSupport::JSON.decode(some_string)
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index 1a95bd63e6..f65c831e04 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -25,9 +25,10 @@ module ActiveSupport
# matches YAML-formatted dates
DATE_REGEX = /^(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}[T \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?))$/
- # Dumps objects in JSON (JavaScript Object Notation). See www.json.org for more info.
+ # Dumps objects in JSON (JavaScript Object Notation).
+ # See www.json.org for more info.
#
- # ActiveSupport::JSON.encode({team: 'rails', players: '36'})
+ # ActiveSupport::JSON.encode({ team: 'rails', players: '36' })
# # => "{\"team\":\"rails\",\"players\":\"36\"}"
def self.encode(value, options = nil)
Encoding::Encoder.new(options).encode(value)
@@ -51,7 +52,7 @@ module ActiveSupport
end
end
- # like encode, but only calls as_json, without encoding to string
+ # like encode, but only calls as_json, without encoding to string.
def as_json(value, use_options = true)
check_for_circular_references(value) do
use_options ? value.as_json(options_for(value)) : value.as_json
@@ -60,7 +61,8 @@ module ActiveSupport
def options_for(value)
if value.is_a?(Array) || value.is_a?(Hash)
- # hashes and arrays need to get encoder in the options, so that they can detect circular references
+ # hashes and arrays need to get encoder in the options, so that
+ # they can detect circular references.
options.merge(:encoder => self)
else
options
@@ -105,10 +107,12 @@ module ActiveSupport
'&' => '\u0026' }
class << self
- # If true, use ISO 8601 format for dates and times. Otherwise, fall back to the Active Support legacy format.
+ # If true, use ISO 8601 format for dates and times. Otherwise, fall back
+ # to the Active Support legacy format.
attr_accessor :use_standard_json_time_format
- # If false, serializes BigDecimal objects as numeric instead of wrapping them in a string
+ # If false, serializes BigDecimal objects as numeric instead of wrapping
+ # them in a string.
attr_accessor :encode_big_decimal_as_string
attr_accessor :escape_regex
@@ -231,11 +235,13 @@ class BigDecimal
# those libraries would get in general a wrong number and no way to recover
# other than manually inspecting the string with the JSON code itself.
#
- # That's why a JSON string is returned. The JSON literal is not numeric, but if
- # the other end knows by contract that the data is supposed to be a BigDecimal,
- # it still has the chance to post-process the string and get the real value.
+ # That's why a JSON string is returned. The JSON literal is not numeric, but
+ # if the other end knows by contract that the data is supposed to be a
+ # BigDecimal, it still has the chance to post-process the string and get the
+ # real value.
#
- # Use ActiveSupport.use_standard_json_big_decimal_format = true to override this behaviour
+ # Use <tt>ActiveSupport.use_standard_json_big_decimal_format = true</tt> to
+ # override this behaviour.
def as_json(options = nil) #:nodoc:
if finite?
ActiveSupport.encode_big_decimal_as_string ? to_s : self