aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-04-26 15:18:33 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2009-04-26 15:18:33 -0700
commit8d64085138b1a2ff36b94267d0236868b287610e (patch)
tree928eba809df85dfe47195f05171d60af3dec6665
parentbe7e21a85c487b6f3bfc2e393387ada5cc52290d (diff)
downloadrails-8d64085138b1a2ff36b94267d0236868b287610e.tar.gz
rails-8d64085138b1a2ff36b94267d0236868b287610e.tar.bz2
rails-8d64085138b1a2ff36b94267d0236868b287610e.zip
Only Object to_json alias is needed. Prefer nil options.
-rw-r--r--actionpack/lib/action_view/helpers/prototype_helper.rb2
-rw-r--r--activesupport/lib/active_support/json/encoders/date.rb2
-rw-r--r--activesupport/lib/active_support/json/encoders/date_time.rb2
-rw-r--r--activesupport/lib/active_support/json/encoders/enumerable.rb4
-rw-r--r--activesupport/lib/active_support/json/encoders/false_class.rb2
-rw-r--r--activesupport/lib/active_support/json/encoders/hash.rb14
-rw-r--r--activesupport/lib/active_support/json/encoders/nil_class.rb2
-rw-r--r--activesupport/lib/active_support/json/encoders/numeric.rb2
-rw-r--r--activesupport/lib/active_support/json/encoders/object.rb2
-rw-r--r--activesupport/lib/active_support/json/encoders/regexp.rb2
-rw-r--r--activesupport/lib/active_support/json/encoders/string.rb2
-rw-r--r--activesupport/lib/active_support/json/encoders/symbol.rb4
-rw-r--r--activesupport/lib/active_support/json/encoders/time.rb2
-rw-r--r--activesupport/lib/active_support/json/encoders/true_class.rb2
-rw-r--r--activesupport/lib/active_support/json/encoding.rb3
15 files changed, 12 insertions, 35 deletions
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb
index 868c8226c4..9cafd17004 100644
--- a/actionpack/lib/action_view/helpers/prototype_helper.rb
+++ b/actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -1188,8 +1188,6 @@ module ActionView
@variable
end
- alias to_json rails_to_json
-
private
def append_to_function_chain!(call)
@generator << @variable if @empty
diff --git a/activesupport/lib/active_support/json/encoders/date.rb b/activesupport/lib/active_support/json/encoders/date.rb
index 79c3957362..1aebdd2764 100644
--- a/activesupport/lib/active_support/json/encoders/date.rb
+++ b/activesupport/lib/active_support/json/encoders/date.rb
@@ -18,6 +18,4 @@ class Date
%("#{strftime("%Y/%m/%d")}")
end
end
-
- alias to_json rails_to_json
end
diff --git a/activesupport/lib/active_support/json/encoders/date_time.rb b/activesupport/lib/active_support/json/encoders/date_time.rb
index cdfc39b9f3..096e0dd36b 100644
--- a/activesupport/lib/active_support/json/encoders/date_time.rb
+++ b/activesupport/lib/active_support/json/encoders/date_time.rb
@@ -18,6 +18,4 @@ class DateTime
strftime('"%Y/%m/%d %H:%M:%S %z"')
end
end
-
- alias to_json rails_to_json
end
diff --git a/activesupport/lib/active_support/json/encoders/enumerable.rb b/activesupport/lib/active_support/json/encoders/enumerable.rb
index e1c3ec249d..6e0c3b6b9c 100644
--- a/activesupport/lib/active_support/json/encoders/enumerable.rb
+++ b/activesupport/lib/active_support/json/encoders/enumerable.rb
@@ -6,9 +6,7 @@ module Enumerable
# # => users.to_json(:only => :name)
#
# will pass the <tt>:only => :name</tt> option to each user.
- def rails_to_json(options = {}) #:nodoc:
+ def rails_to_json(options = nil) #:nodoc:
"[#{map { |value| ActiveSupport::JSON.encode(value, options) } * ','}]"
end
-
- alias to_json rails_to_json
end
diff --git a/activesupport/lib/active_support/json/encoders/false_class.rb b/activesupport/lib/active_support/json/encoders/false_class.rb
index a7657cca37..4c47b3372e 100644
--- a/activesupport/lib/active_support/json/encoders/false_class.rb
+++ b/activesupport/lib/active_support/json/encoders/false_class.rb
@@ -2,6 +2,4 @@ class FalseClass
def rails_to_json(options = nil) #:nodoc:
'false'
end
-
- alias to_json rails_to_json
end
diff --git a/activesupport/lib/active_support/json/encoders/hash.rb b/activesupport/lib/active_support/json/encoders/hash.rb
index 19b97d7b8c..cd8639c1dd 100644
--- a/activesupport/lib/active_support/json/encoders/hash.rb
+++ b/activesupport/lib/active_support/json/encoders/hash.rb
@@ -30,13 +30,15 @@ class Hash
# would pass the <tt>:include => :posts</tt> option to <tt>users</tt>,
# allowing the posts association in the User model to be converted to JSON
# as well.
- def rails_to_json(options = {}) #:nodoc:
+ def rails_to_json(options = nil) #:nodoc:
hash_keys = self.keys
- if except = options[:except]
- hash_keys = hash_keys - Array.wrap(except)
- elsif only = options[:only]
- hash_keys = hash_keys & Array.wrap(only)
+ if options
+ if except = options[:except]
+ hash_keys = hash_keys - Array.wrap(except)
+ elsif only = options[:only]
+ hash_keys = hash_keys & Array.wrap(only)
+ end
end
result = '{'
@@ -45,6 +47,4 @@ class Hash
end * ','
result << '}'
end
-
- alias to_json rails_to_json
end
diff --git a/activesupport/lib/active_support/json/encoders/nil_class.rb b/activesupport/lib/active_support/json/encoders/nil_class.rb
index b31e1dd249..b7b63e26d5 100644
--- a/activesupport/lib/active_support/json/encoders/nil_class.rb
+++ b/activesupport/lib/active_support/json/encoders/nil_class.rb
@@ -2,6 +2,4 @@ class NilClass
def rails_to_json(options = nil) #:nodoc:
'null'
end
-
- alias to_json rails_to_json
end
diff --git a/activesupport/lib/active_support/json/encoders/numeric.rb b/activesupport/lib/active_support/json/encoders/numeric.rb
index 491b330c39..b969902da0 100644
--- a/activesupport/lib/active_support/json/encoders/numeric.rb
+++ b/activesupport/lib/active_support/json/encoders/numeric.rb
@@ -2,6 +2,4 @@ class Numeric
def rails_to_json(options = nil) #:nodoc:
to_s
end
-
- alias to_json rails_to_json
end
diff --git a/activesupport/lib/active_support/json/encoders/object.rb b/activesupport/lib/active_support/json/encoders/object.rb
index d68f50562e..57603bd1e6 100644
--- a/activesupport/lib/active_support/json/encoders/object.rb
+++ b/activesupport/lib/active_support/json/encoders/object.rb
@@ -2,7 +2,7 @@ require 'active_support/core_ext/object/instance_variables'
class Object
# Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info.
- def rails_to_json(options = {})
+ def rails_to_json(options = nil)
ActiveSupport::JSON.encode(instance_values, options)
end
diff --git a/activesupport/lib/active_support/json/encoders/regexp.rb b/activesupport/lib/active_support/json/encoders/regexp.rb
index 63ccd7c490..ff7dd67544 100644
--- a/activesupport/lib/active_support/json/encoders/regexp.rb
+++ b/activesupport/lib/active_support/json/encoders/regexp.rb
@@ -2,6 +2,4 @@ class Regexp
def rails_to_json(options = nil) #:nodoc:
inspect
end
-
- alias to_json rails_to_json
end
diff --git a/activesupport/lib/active_support/json/encoders/string.rb b/activesupport/lib/active_support/json/encoders/string.rb
index 27bef3b9cc..da16111fd5 100644
--- a/activesupport/lib/active_support/json/encoders/string.rb
+++ b/activesupport/lib/active_support/json/encoders/string.rb
@@ -33,6 +33,4 @@ class String
s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/, '\\\\u\&')
} + '"'
end
-
- alias to_json rails_to_json
end
diff --git a/activesupport/lib/active_support/json/encoders/symbol.rb b/activesupport/lib/active_support/json/encoders/symbol.rb
index 6487bf8cb7..c39eda81c1 100644
--- a/activesupport/lib/active_support/json/encoders/symbol.rb
+++ b/activesupport/lib/active_support/json/encoders/symbol.rb
@@ -1,7 +1,5 @@
class Symbol
- def rails_to_json(options = {}) #:nodoc:
+ def rails_to_json(options = nil) #:nodoc:
ActiveSupport::JSON.encode(to_s, options)
end
-
- alias to_json rails_to_json
end
diff --git a/activesupport/lib/active_support/json/encoders/time.rb b/activesupport/lib/active_support/json/encoders/time.rb
index 2699672949..1cb0808490 100644
--- a/activesupport/lib/active_support/json/encoders/time.rb
+++ b/activesupport/lib/active_support/json/encoders/time.rb
@@ -20,6 +20,4 @@ class Time
%("#{strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}")
end
end
-
- alias to_json rails_to_json
end
diff --git a/activesupport/lib/active_support/json/encoders/true_class.rb b/activesupport/lib/active_support/json/encoders/true_class.rb
index ac7c7d1e87..a22c487a93 100644
--- a/activesupport/lib/active_support/json/encoders/true_class.rb
+++ b/activesupport/lib/active_support/json/encoders/true_class.rb
@@ -2,6 +2,4 @@ class TrueClass
def rails_to_json(options = nil) #:nodoc:
'true'
end
-
- alias to_json rails_to_json
end
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index e8e9308495..acccb62aea 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -4,7 +4,8 @@ module ActiveSupport
end
# Converts a Ruby object into a JSON string.
- def self.encode(value, options = {})
+ def self.encode(value, options = nil)
+ options ||= {}
seen = (options[:seen] ||= [])
raise CircularReferenceError, 'object references itself' if seen.include?(value.object_id)
seen << value.object_id