Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Only Object to_json alias is needed. Prefer nil options.

  • Loading branch information...
commit 8d64085138b1a2ff36b94267d0236868b287610e 1 parent be7e21a
@jeremy jeremy authored
View
2  actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -1188,8 +1188,6 @@ def rails_to_json(options = nil)
@variable
end
- alias to_json rails_to_json
-
private
def append_to_function_chain!(call)
@generator << @variable if @empty
View
2  activesupport/lib/active_support/json/encoders/date.rb
@@ -18,6 +18,4 @@ def rails_to_json(options = nil)
%("#{strftime("%Y/%m/%d")}")
end
end
-
- alias to_json rails_to_json
end
View
2  activesupport/lib/active_support/json/encoders/date_time.rb
@@ -18,6 +18,4 @@ def rails_to_json(options = nil)
strftime('"%Y/%m/%d %H:%M:%S %z"')
end
end
-
- alias to_json rails_to_json
end
View
4 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
View
2  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
View
14 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 @@ def rails_to_json(options = {}) #:nodoc:
end * ','
result << '}'
end
-
- alias to_json rails_to_json
end
View
2  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
View
2  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
View
2  activesupport/lib/active_support/json/encoders/object.rb
@@ -2,7 +2,7 @@
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
View
2  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
View
2  activesupport/lib/active_support/json/encoders/string.rb
@@ -33,6 +33,4 @@ def rails_to_json(options = nil) #:nodoc:
s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/, '\\\\u\&')
} + '"'
end
-
- alias to_json rails_to_json
end
View
4 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
View
2  activesupport/lib/active_support/json/encoders/time.rb
@@ -20,6 +20,4 @@ def rails_to_json(options = nil)
%("#{strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}")
end
end
-
- alias to_json rails_to_json
end
View
2  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
View
3  activesupport/lib/active_support/json/encoding.rb
@@ -4,7 +4,8 @@ class CircularReferenceError < StandardError
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
Please sign in to comment.
Something went wrong with that request. Please try again.