aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-04-23 14:34:37 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-04-23 14:34:37 +0100
commitae812c0a7bdb876c03752adfaa980ac4e74f2e17 (patch)
tree73eba5b0ddce60a4578fcbf6be581b8f35488273 /activesupport/lib
parent67f30fd9639409877a57a7ba758cd13496433d69 (diff)
parent3c4c6bd0df598f865f49a983b4c65c415af4bcfc (diff)
downloadrails-ae812c0a7bdb876c03752adfaa980ac4e74f2e17.tar.gz
rails-ae812c0a7bdb876c03752adfaa980ac4e74f2e17.tar.bz2
rails-ae812c0a7bdb876c03752adfaa980ac4e74f2e17.zip
Merge commit 'mainstream/master'
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/cache.rb1
-rw-r--r--activesupport/lib/active_support/cache/strategy/local_cache.rb2
-rw-r--r--activesupport/lib/active_support/callbacks.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/array/conversions.rb6
-rw-r--r--activesupport/lib/active_support/core_ext/class/attribute_accessors.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/class/delegating_attributes.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb4
-rw-r--r--activesupport/lib/active_support/core_ext/class/removal.rb3
-rw-r--r--activesupport/lib/active_support/core_ext/date/calculations.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/date/conversions.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/date_time.rb3
-rw-r--r--activesupport/lib/active_support/core_ext/hash/conversions.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/logger.rb5
-rw-r--r--activesupport/lib/active_support/core_ext/module/attr_internal.rb8
-rw-r--r--activesupport/lib/active_support/core_ext/module/introspection.rb6
-rw-r--r--activesupport/lib/active_support/core_ext/module/model_naming.rb8
-rw-r--r--activesupport/lib/active_support/core_ext/module/synchronization.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/numeric/time.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/object.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/range/blockless_step.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/string/conversions.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/string/multibyte.rb1
-rw-r--r--activesupport/lib/active_support/dependencies.rb8
-rw-r--r--activesupport/lib/active_support/deprecation/method_wrappers.rb1
-rw-r--r--activesupport/lib/active_support/deprecation/proxy_wrappers.rb4
-rw-r--r--activesupport/lib/active_support/duration.rb1
-rw-r--r--activesupport/lib/active_support/inflector.rb3
-rw-r--r--activesupport/lib/active_support/json.rb34
-rw-r--r--activesupport/lib/active_support/json/backends/jsongem.rb36
-rw-r--r--activesupport/lib/active_support/json/backends/yaml.rb83
-rw-r--r--activesupport/lib/active_support/json/decoding.rb82
-rw-r--r--activesupport/lib/active_support/json/encoders/date.rb4
-rw-r--r--activesupport/lib/active_support/json/encoders/date_time.rb4
-rw-r--r--activesupport/lib/active_support/json/encoders/enumerable.rb6
-rw-r--r--activesupport/lib/active_support/json/encoders/false_class.rb4
-rw-r--r--activesupport/lib/active_support/json/encoders/hash.rb8
-rw-r--r--activesupport/lib/active_support/json/encoders/nil_class.rb4
-rw-r--r--activesupport/lib/active_support/json/encoders/numeric.rb4
-rw-r--r--activesupport/lib/active_support/json/encoders/object.rb4
-rw-r--r--activesupport/lib/active_support/json/encoders/regexp.rb4
-rw-r--r--activesupport/lib/active_support/json/encoders/string.rb4
-rw-r--r--activesupport/lib/active_support/json/encoders/symbol.rb4
-rw-r--r--activesupport/lib/active_support/json/encoders/time.rb6
-rw-r--r--activesupport/lib/active_support/json/encoders/true_class.rb4
-rw-r--r--activesupport/lib/active_support/json/encoding.rb2
-rw-r--r--activesupport/lib/active_support/json/variable.rb2
-rw-r--r--activesupport/lib/active_support/memoizable.rb2
-rw-r--r--activesupport/lib/active_support/multibyte.rb2
-rw-r--r--activesupport/lib/active_support/new_callbacks.rb3
-rw-r--r--activesupport/lib/active_support/testing/assertions.rb2
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb6
-rw-r--r--activesupport/lib/active_support/xml_mini.rb2
-rw-r--r--activesupport/lib/active_support/xml_mini/rexml.rb2
53 files changed, 277 insertions, 125 deletions
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb
index 4b2eebb007..feb6b1f2cf 100644
--- a/activesupport/lib/active_support/cache.rb
+++ b/activesupport/lib/active_support/cache.rb
@@ -2,6 +2,7 @@ require 'benchmark'
require 'active_support/core_ext/benchmark'
require 'active_support/core_ext/exception'
require 'active_support/core_ext/class/attribute_accessors'
+require 'active_support/core_ext' # FIXME: pulling in all to_param extensions
module ActiveSupport
# See ActiveSupport::Cache::Store for documentation.
diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb
index 84d9a0e6d8..4bbcd8e4c4 100644
--- a/activesupport/lib/active_support/cache/strategy/local_cache.rb
+++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/duplicable'
+
module ActiveSupport
module Cache
module Strategy
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 4bac8292e2..f049189b9a 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/array/extract_options'
+
module ActiveSupport
# Callbacks are hooks into the lifecycle of an object that allow you to trigger logic
# before or after an alteration of the object state.
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb
index 81e466779e..5f1ce4142f 100644
--- a/activesupport/lib/active_support/core_ext/array/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -1,3 +1,7 @@
+require 'active_support/core_ext/hash/keys'
+require 'active_support/core_ext/hash/reverse_merge'
+require 'active_support/inflector'
+
class Array
# Converts the array to a comma-separated sentence where the last element is joined by the connector word. Options:
# * <tt>:words_connector</tt> - The sign or word used to join the elements in arrays with two or more elements (default: ", ")
@@ -155,7 +159,7 @@ class Array
raise "Not all elements respond to to_xml" unless all? { |e| e.respond_to? :to_xml }
require 'builder' unless defined?(Builder)
- options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize : "records"
+ options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? ActiveSupport::Inflector.pluralize(ActiveSupport::Inflector.underscore(first.class.name)) : "records"
options[:children] ||= options[:root].singularize
options[:indent] ||= 2
options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
diff --git a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
index 75e481fc54..74ce85a1c2 100644
--- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
+++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/array/extract_options'
+
# Extends the class object with class and instance accessors for class attributes,
# just like the native attr* accessors for instance attributes.
#
diff --git a/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb b/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
index b0784d8416..fd029544c3 100644
--- a/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
+++ b/activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
@@ -1,4 +1,4 @@
-require 'active_support/core_ext/blank'
+require 'active_support/core_ext/object/blank'
class Class
def superclass_delegating_reader(*names)
diff --git a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
index 2f18666ab9..cca93a0b9f 100644
--- a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
+++ b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/duplicable'
+
# Retain for backward compatibility. Methods are now included in Class.
module ClassInheritableAttributes # :nodoc:
end
@@ -216,4 +218,4 @@ class Class
extlib_inheritable_reader(*syms)
extlib_inheritable_writer(*syms)
end
-end \ No newline at end of file
+end
diff --git a/activesupport/lib/active_support/core_ext/class/removal.rb b/activesupport/lib/active_support/core_ext/class/removal.rb
index 10660edb2c..2dea3c24d5 100644
--- a/activesupport/lib/active_support/core_ext/class/removal.rb
+++ b/activesupport/lib/active_support/core_ext/class/removal.rb
@@ -1,3 +1,6 @@
+require 'active_support/core_ext/object/extending'
+require 'active_support/core_ext/module/introspection'
+
class Class #:nodoc:
# Unassociates the class with its subclasses and removes the subclasses
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb
index 59efdbd1b6..04a32edefd 100644
--- a/activesupport/lib/active_support/core_ext/date/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -1,3 +1,5 @@
+require 'active_support/duration'
+
class Date
class << self
# Returns a new Date representing the date 1 day ago (i.e. yesterday's date).
diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb
index f6c870035b..54facf4430 100644
--- a/activesupport/lib/active_support/core_ext/date/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/date/conversions.rb
@@ -1,4 +1,6 @@
require 'active_support/inflector'
+require 'active_support/core_ext/time/conversions'
+require 'active_support/core_ext/date_time/conversions'
class Date
DATE_FORMATS = {
diff --git a/activesupport/lib/active_support/core_ext/date_time.rb b/activesupport/lib/active_support/core_ext/date_time.rb
index 83a11da1c7..004fd0ad29 100644
--- a/activesupport/lib/active_support/core_ext/date_time.rb
+++ b/activesupport/lib/active_support/core_ext/date_time.rb
@@ -1,5 +1,4 @@
-require 'date'
-
+require 'active_support/core_ext/time'
require 'active_support/core_ext/date_time/acts_like'
require 'active_support/core_ext/date_time/calculations'
require 'active_support/core_ext/date_time/conversions'
diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb
index fa171720f9..f9dddec687 100644
--- a/activesupport/lib/active_support/core_ext/hash/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -1,6 +1,8 @@
require 'date'
require 'active_support/core_ext/object/conversions'
require 'active_support/core_ext/array/conversions'
+require 'active_support/core_ext/hash/reverse_merge'
+require 'active_support/core/time'
class Hash
# This module exists to decorate files deserialized using Hash.from_xml with
diff --git a/activesupport/lib/active_support/core_ext/logger.rb b/activesupport/lib/active_support/core_ext/logger.rb
index 858da7aa07..22749229a3 100644
--- a/activesupport/lib/active_support/core_ext/logger.rb
+++ b/activesupport/lib/active_support/core_ext/logger.rb
@@ -1,6 +1,7 @@
-# Adds the 'around_level' method to Logger.
+require 'active_support/core_ext/class/attribute_accessors'
-class Logger
+# Adds the 'around_level' method to Logger.
+class Logger #:nodoc:
def self.define_around_helper(level)
module_eval <<-end_eval
def around_#{level}(before_message, after_message, &block) # def around_debug(before_message, after_message, &block)
diff --git a/activesupport/lib/active_support/core_ext/module/attr_internal.rb b/activesupport/lib/active_support/core_ext/module/attr_internal.rb
index b66c0d7500..d052bfed2d 100644
--- a/activesupport/lib/active_support/core_ext/module/attr_internal.rb
+++ b/activesupport/lib/active_support/core_ext/module/attr_internal.rb
@@ -22,11 +22,11 @@ class Module
alias_method :attr_internal, :attr_internal_accessor
- private
- mattr_accessor :attr_internal_naming_format
- self.attr_internal_naming_format = '@_%s'
+ class << self; attr_accessor :attr_internal_naming_format end
+ self.attr_internal_naming_format = '@_%s'
+ private
def attr_internal_ivar_name(attr)
- attr_internal_naming_format % attr
+ Module.attr_internal_naming_format % attr
end
end
diff --git a/activesupport/lib/active_support/core_ext/module/introspection.rb b/activesupport/lib/active_support/core_ext/module/introspection.rb
index 7708d573fa..23a1063901 100644
--- a/activesupport/lib/active_support/core_ext/module/introspection.rb
+++ b/activesupport/lib/active_support/core_ext/module/introspection.rb
@@ -1,3 +1,5 @@
+require 'active_support/inflector'
+
class Module
# Returns the name of the module containing this one.
#
@@ -26,7 +28,7 @@ class Module
# p Module.new.parent # => Object
#
def parent
- parent_name ? parent_name.constantize : Object
+ parent_name ? ActiveSupport::Inflector.constantize(parent_name) : Object
end
# Returns all the parents of this module according to its name, ordered from
@@ -47,7 +49,7 @@ class Module
if parent_name
parts = parent_name.split('::')
until parts.empty?
- parents << (parts * '::').constantize
+ parents << ActiveSupport::Inflector.constantize(parts * '::')
parts.pop
end
end
diff --git a/activesupport/lib/active_support/core_ext/module/model_naming.rb b/activesupport/lib/active_support/core_ext/module/model_naming.rb
index 004b96a3c1..36fde87b23 100644
--- a/activesupport/lib/active_support/core_ext/module/model_naming.rb
+++ b/activesupport/lib/active_support/core_ext/module/model_naming.rb
@@ -1,13 +1,15 @@
+require 'active_support/inflector'
+
module ActiveSupport
class ModelName < String
attr_reader :singular, :plural, :cache_key, :partial_path
def initialize(name)
super
- @singular = underscore.tr('/', '_').freeze
- @plural = @singular.pluralize.freeze
+ @singular = ActiveSupport::Inflector.underscore(self).tr('/', '_').freeze
+ @plural = ActiveSupport::Inflector.pluralize(@singular).freeze
@cache_key = tableize.freeze
- @partial_path = "#{@cache_key}/#{demodulize.underscore}".freeze
+ @partial_path = "#{@cache_key}/#{ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self))}".freeze
end
end
end
diff --git a/activesupport/lib/active_support/core_ext/module/synchronization.rb b/activesupport/lib/active_support/core_ext/module/synchronization.rb
index 069db3fed0..f72d512340 100644
--- a/activesupport/lib/active_support/core_ext/module/synchronization.rb
+++ b/activesupport/lib/active_support/core_ext/module/synchronization.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/module/aliasing'
+
class Module
# Synchronize access around a method, delegating synchronization to a
# particular mutex. A mutex (either a Mutex, or any object that responds to
diff --git a/activesupport/lib/active_support/core_ext/numeric/time.rb b/activesupport/lib/active_support/core_ext/numeric/time.rb
index 2955e8ff1d..d1062805c5 100644
--- a/activesupport/lib/active_support/core_ext/numeric/time.rb
+++ b/activesupport/lib/active_support/core_ext/numeric/time.rb
@@ -1,3 +1,5 @@
+require 'active_support/duration'
+
class Numeric
# Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years.
#
diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb
index 96385d2b87..04e8f06b3d 100644
--- a/activesupport/lib/active_support/core_ext/object.rb
+++ b/activesupport/lib/active_support/core_ext/object.rb
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/object/acts_like'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/object/duplicable'
require 'active_support/core_ext/object/try'
diff --git a/activesupport/lib/active_support/core_ext/range/blockless_step.rb b/activesupport/lib/active_support/core_ext/range/blockless_step.rb
index f4792d03b7..db42ef5c47 100644
--- a/activesupport/lib/active_support/core_ext/range/blockless_step.rb
+++ b/activesupport/lib/active_support/core_ext/range/blockless_step.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/module/aliasing'
+
class Range
begin
(1..2).step
diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb
index 39c2b1b8ed..3f05db62c3 100644
--- a/activesupport/lib/active_support/core_ext/string/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/string/conversions.rb
@@ -1,4 +1,5 @@
require 'date'
+require 'active_support/core_ext/time/calculations'
class String
# 'a'.ord == 'a'[0] for Ruby 1.9 forward compatibility.
diff --git a/activesupport/lib/active_support/core_ext/string/multibyte.rb b/activesupport/lib/active_support/core_ext/string/multibyte.rb
index 0f0dfb2443..13208c6ee2 100644
--- a/activesupport/lib/active_support/core_ext/string/multibyte.rb
+++ b/activesupport/lib/active_support/core_ext/string/multibyte.rb
@@ -1,4 +1,5 @@
# encoding: utf-8
+require 'active_support/multibyte'
class String
unless '1.9'.respond_to?(:force_encoding)
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index 1804c14618..855b720ef1 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -1,11 +1,13 @@
require 'set'
require 'thread'
-require 'active_support/inflector'
-require 'active_support/core_ext/name_error'
-require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/module/aliasing'
require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/module/introspection'
+require 'active_support/core_ext/object/blank'
+require 'active_support/core_ext/load_error'
+require 'active_support/core_ext/name_error'
+require 'active_support/core_ext/string/starts_ends_with'
+require 'active_support/inflector'
module ActiveSupport #:nodoc:
module Dependencies #:nodoc:
diff --git a/activesupport/lib/active_support/deprecation/method_wrappers.rb b/activesupport/lib/active_support/deprecation/method_wrappers.rb
index b35d4daf9a..b9eb539aa7 100644
--- a/activesupport/lib/active_support/deprecation/method_wrappers.rb
+++ b/activesupport/lib/active_support/deprecation/method_wrappers.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/module/deprecation'
+require 'active_support/core_ext/module/aliasing'
module ActiveSupport
class << Deprecation
diff --git a/activesupport/lib/active_support/deprecation/proxy_wrappers.rb b/activesupport/lib/active_support/deprecation/proxy_wrappers.rb
index 1c268d0d9c..ec54efe08e 100644
--- a/activesupport/lib/active_support/deprecation/proxy_wrappers.rb
+++ b/activesupport/lib/active_support/deprecation/proxy_wrappers.rb
@@ -1,3 +1,5 @@
+require 'active_support/inflector'
+
module ActiveSupport
module Deprecation
class DeprecationProxy #:nodoc:
@@ -61,7 +63,7 @@ module ActiveSupport
private
def target
- @new_const.to_s.constantize
+ ActiveSupport::Inflector.constantize(@new_const.to_s)
end
def warn(callstack, called, args)
diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb
index f64661c5b1..a33586f77f 100644
--- a/activesupport/lib/active_support/duration.rb
+++ b/activesupport/lib/active_support/duration.rb
@@ -1,4 +1,5 @@
require 'active_support/basic_object'
+require 'active_support/core_ext/array/conversions'
module ActiveSupport
# Provides accurate date and time measurements using Date#advance and
diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb
index 614afa1bd6..ff70d6d76e 100644
--- a/activesupport/lib/active_support/inflector.rb
+++ b/activesupport/lib/active_support/inflector.rb
@@ -1,6 +1,7 @@
# encoding: utf-8
require 'iconv'
-
+require 'active_support/core_ext/object/blank'
+require 'active_support/core_ext/string/access'
require 'active_support/core_ext/string/multibyte'
module ActiveSupport
diff --git a/activesupport/lib/active_support/json.rb b/activesupport/lib/active_support/json.rb
index 91f19f8a70..fc433de582 100644
--- a/activesupport/lib/active_support/json.rb
+++ b/activesupport/lib/active_support/json.rb
@@ -1,8 +1,37 @@
+require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/module/attribute_accessors'
module ActiveSupport
# If true, use ISO 8601 format for dates and times. Otherwise, fall back to the Active Support legacy format.
mattr_accessor :use_standard_json_time_format
+ # Look for and parse json strings that look like ISO 8601 times.
+ mattr_accessor :parse_json_times
+
+ module JSON
+ # matches YAML-formatted dates
+ DATE_REGEX = /^(?:\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})?))$/
+
+ class << self
+ attr_reader :backend
+ delegate :decode, :to => :backend
+
+ def backend=(name)
+ if name.is_a?(Module)
+ @backend = name
+ else
+ require "active_support/json/backends/#{name.to_s.downcase}.rb"
+ @backend = ActiveSupport::JSON::Backends::const_get(name)
+ end
+ end
+
+ def with_backend(name)
+ old_backend, self.backend = backend, name
+ yield
+ ensure
+ self.backend = old_backend
+ end
+ end
+ end
class << self
def escape_html_entities_in_json
@@ -19,7 +48,8 @@ module ActiveSupport
@escape_html_entities_in_json = value
end
end
+
+ JSON.backend = 'Yaml'
end
-require 'active_support/json/encoding'
-require 'active_support/json/decoding'
+require 'active_support/json/encoding' \ No newline at end of file
diff --git a/activesupport/lib/active_support/json/backends/jsongem.rb b/activesupport/lib/active_support/json/backends/jsongem.rb
new file mode 100644
index 0000000000..de847e30a3
--- /dev/null
+++ b/activesupport/lib/active_support/json/backends/jsongem.rb
@@ -0,0 +1,36 @@
+module ActiveSupport
+ module JSON
+ ParseError = ::JSON::ParserError
+
+ module Backends
+ module JSONGem
+ extend self
+
+ # Converts a JSON string into a Ruby object.
+ def decode(json)
+ data = ::JSON.parse(json)
+ if ActiveSupport.parse_json_times
+ convert_dates_from(data)
+ else
+ data
+ end
+ end
+
+ private
+ def convert_dates_from(data)
+ case data
+ when DATE_REGEX
+ DateTime.parse(data)
+ when Array
+ data.map! { |d| convert_dates_from(d) }
+ when Hash
+ data.each do |key, value|
+ data[key] = convert_dates_from(value)
+ end
+ else data
+ end
+ end
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/activesupport/lib/active_support/json/backends/yaml.rb b/activesupport/lib/active_support/json/backends/yaml.rb
new file mode 100644
index 0000000000..c7db508c23
--- /dev/null
+++ b/activesupport/lib/active_support/json/backends/yaml.rb
@@ -0,0 +1,83 @@
+require 'active_support/core_ext/string/starts_ends_with'
+
+module ActiveSupport
+ module JSON
+ class ParseError < StandardError
+ end
+
+ module Backends
+ module Yaml
+ extend self
+
+ # Converts a JSON string into a Ruby object.
+ def decode(json)
+ YAML.load(convert_json_to_yaml(json))
+ rescue ArgumentError => e
+ raise ParseError, "Invalid JSON string"
+ end
+
+ protected
+ # Ensure that ":" and "," are always followed by a space
+ def convert_json_to_yaml(json) #:nodoc:
+ require 'strscan' unless defined? ::StringScanner
+ scanner, quoting, marks, pos, times = ::StringScanner.new(json), false, [], nil, []
+ while scanner.scan_until(/(\\['"]|['":,\\]|\\.)/)
+ case char = scanner[1]
+ when '"', "'"
+ if !quoting
+ quoting = char
+ pos = scanner.pos
+ elsif quoting == char
+ if json[pos..scanner.pos-2] =~ DATE_REGEX
+ # found a date, track the exact positions of the quotes so we can remove them later.
+ # oh, and increment them for each current mark, each one is an extra padded space that bumps
+ # the position in the final YAML output
+ total_marks = marks.size
+ times << pos+total_marks << scanner.pos+total_marks
+ end
+ quoting = false
+ end
+ when ":",","
+ marks << scanner.pos - 1 unless quoting
+ end
+ end
+
+ if marks.empty?
+ json.gsub(/\\([\\\/]|u[[:xdigit:]]{4})/) do
+ ustr = $1
+ if ustr.start_with?('u')
+ [ustr[1..-1].to_i(16)].pack("U")
+ elsif ustr == '\\'
+ '\\\\'
+ else
+ ustr
+ end
+ end
+ else
+ left_pos = [-1].push(*marks)
+ right_pos = marks << scanner.pos + scanner.rest_size
+ output = []
+ left_pos.each_with_index do |left, i|
+ scanner.pos = left.succ
+ output << scanner.peek(right_pos[i] - scanner.pos + 1).gsub(/\\([\\\/]|u[[:xdigit:]]{4})/) do
+ ustr = $1
+ if ustr.start_with?('u')
+ [ustr[1..-1].to_i(16)].pack("U")
+ elsif ustr == '\\'
+ '\\\\'
+ else
+ ustr
+ end
+ end
+ end
+ output = output * " "
+
+ times.each { |i| output[i-1] = ' ' }
+ output.gsub!(/\\\//, '/')
+ output
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb
deleted file mode 100644
index 70e9f40fc7..0000000000
--- a/activesupport/lib/active_support/json/decoding.rb
+++ /dev/null
@@ -1,82 +0,0 @@
-require 'active_support/core_ext/string/starts_ends_with'
-
-module ActiveSupport
- module JSON
- class ParseError < StandardError
- end
-
- class << self
- # Converts a JSON string into a Ruby object.
- def decode(json)
- YAML.load(convert_json_to_yaml(json))
- rescue ArgumentError => e
- raise ParseError, "Invalid JSON string"
- end
-
- protected
- # matches YAML-formatted dates
- DATE_REGEX = /^(?:\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})?)?)$/
-
- # Ensure that ":" and "," are always followed by a space
- def convert_json_to_yaml(json) #:nodoc:
- require 'strscan' unless defined? ::StringScanner
- scanner, quoting, marks, pos, times = ::StringScanner.new(json), false, [], nil, []
- while scanner.scan_until(/(\\['"]|['":,\\]|\\.)/)
- case char = scanner[1]
- when '"', "'"
- if !quoting
- quoting = char
- pos = scanner.pos
- elsif quoting == char
- if json[pos..scanner.pos-2] =~ DATE_REGEX
- # found a date, track the exact positions of the quotes so we can remove them later.
- # oh, and increment them for each current mark, each one is an extra padded space that bumps
- # the position in the final YAML output
- total_marks = marks.size
- times << pos+total_marks << scanner.pos+total_marks
- end
- quoting = false
- end
- when ":",","
- marks << scanner.pos - 1 unless quoting
- end
- end
-
- if marks.empty?
- json.gsub(/\\([\\\/]|u[[:xdigit:]]{4})/) do
- ustr = $1
- if ustr.start_with?('u')
- [ustr[1..-1].to_i(16)].pack("U")
- elsif ustr == '\\'
- '\\\\'
- else
- ustr
- end
- end
- else
- left_pos = [-1].push(*marks)
- right_pos = marks << scanner.pos + scanner.rest_size
- output = []
- left_pos.each_with_index do |left, i|
- scanner.pos = left.succ
- output << scanner.peek(right_pos[i] - scanner.pos + 1).gsub(/\\([\\\/]|u[[:xdigit:]]{4})/) do
- ustr = $1
- if ustr.start_with?('u')
- [ustr[1..-1].to_i(16)].pack("U")
- elsif ustr == '\\'
- '\\\\'
- else
- ustr
- end
- end
- end
- output = output * " "
-
- times.each { |i| output[i-1] = ' ' }
- output.gsub!(/\\\//, '/')
- output
- end
- end
- end
- end
-end
diff --git a/activesupport/lib/active_support/json/encoders/date.rb b/activesupport/lib/active_support/json/encoders/date.rb
index cc84de1388..79c3957362 100644
--- a/activesupport/lib/active_support/json/encoders/date.rb
+++ b/activesupport/lib/active_support/json/encoders/date.rb
@@ -11,11 +11,13 @@ class Date
# # With ActiveSupport.use_standard_json_time_format = false
# Date.new(2005,2,1).to_json
# # => "2005/02/01"
- def to_json(options = nil)
+ def rails_to_json(options = nil)
if ActiveSupport.use_standard_json_time_format
%("#{strftime("%Y-%m-%d")}")
else
%("#{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 6c85824105..cdfc39b9f3 100644
--- a/activesupport/lib/active_support/json/encoders/date_time.rb
+++ b/activesupport/lib/active_support/json/encoders/date_time.rb
@@ -11,11 +11,13 @@ class DateTime
# # With ActiveSupport.use_standard_json_time_format = false
# DateTime.civil(2005,2,1,15,15,10).to_json
# # => "2005/02/01 15:15:10 +0000"
- def to_json(options = nil)
+ def rails_to_json(options = nil)
if ActiveSupport.use_standard_json_time_format
xmlschema.inspect
else
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 881b1d62c1..e1c3ec249d 100644
--- a/activesupport/lib/active_support/json/encoders/enumerable.rb
+++ b/activesupport/lib/active_support/json/encoders/enumerable.rb
@@ -6,7 +6,9 @@ module Enumerable
# # => users.to_json(:only => :name)
#
# will pass the <tt>:only => :name</tt> option to each user.
- def to_json(options = {}) #:nodoc:
- "[#{map { |value| ActiveSupport::JSON.encode(value, options) } * ', '}]"
+ def rails_to_json(options = {}) #: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 bf0844334b..a7657cca37 100644
--- a/activesupport/lib/active_support/json/encoders/false_class.rb
+++ b/activesupport/lib/active_support/json/encoders/false_class.rb
@@ -1,5 +1,7 @@
class FalseClass
- def to_json(options = nil) #:nodoc:
+ 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 d87b880743..19b97d7b8c 100644
--- a/activesupport/lib/active_support/json/encoders/hash.rb
+++ b/activesupport/lib/active_support/json/encoders/hash.rb
@@ -30,7 +30,7 @@ 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 to_json(options = {}) #:nodoc:
+ def rails_to_json(options = {}) #:nodoc:
hash_keys = self.keys
if except = options[:except]
@@ -41,8 +41,10 @@ class Hash
result = '{'
result << hash_keys.map do |key|
- "#{ActiveSupport::JSON.encode(key.to_s)}: #{ActiveSupport::JSON.encode(self[key], options)}"
- end * ', '
+ "#{ActiveSupport::JSON.encode(key.to_s)}:#{ActiveSupport::JSON.encode(self[key], options)}"
+ 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 4763471ac4..b31e1dd249 100644
--- a/activesupport/lib/active_support/json/encoders/nil_class.rb
+++ b/activesupport/lib/active_support/json/encoders/nil_class.rb
@@ -1,5 +1,7 @@
class NilClass
- def to_json(options = nil) #:nodoc:
+ 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 38713fb369..491b330c39 100644
--- a/activesupport/lib/active_support/json/encoders/numeric.rb
+++ b/activesupport/lib/active_support/json/encoders/numeric.rb
@@ -1,5 +1,7 @@
class Numeric
- def to_json(options = nil) #:nodoc:
+ 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 0475967aee..d68f50562e 100644
--- a/activesupport/lib/active_support/json/encoders/object.rb
+++ b/activesupport/lib/active_support/json/encoders/object.rb
@@ -2,7 +2,9 @@ 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 to_json(options = {})
+ def rails_to_json(options = {})
ActiveSupport::JSON.encode(instance_values, options)
end
+
+ alias to_json rails_to_json
end
diff --git a/activesupport/lib/active_support/json/encoders/regexp.rb b/activesupport/lib/active_support/json/encoders/regexp.rb
index b6116b70b5..63ccd7c490 100644
--- a/activesupport/lib/active_support/json/encoders/regexp.rb
+++ b/activesupport/lib/active_support/json/encoders/regexp.rb
@@ -1,5 +1,7 @@
class Regexp
- def to_json(options = nil) #:nodoc:
+ 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 5ef797955a..27bef3b9cc 100644
--- a/activesupport/lib/active_support/json/encoders/string.rb
+++ b/activesupport/lib/active_support/json/encoders/string.rb
@@ -22,7 +22,7 @@ end
ActiveSupport.escape_html_entities_in_json = true
class String
- def to_json(options = nil) #:nodoc:
+ def rails_to_json(options = nil) #:nodoc:
json = '"' + gsub(ActiveSupport::JSON::Encoding.escape_regex) { |s|
ActiveSupport::JSON::Encoding::ESCAPED_CHARS[s]
}
@@ -33,4 +33,6 @@ 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 485112f97c..6487bf8cb7 100644
--- a/activesupport/lib/active_support/json/encoders/symbol.rb
+++ b/activesupport/lib/active_support/json/encoders/symbol.rb
@@ -1,5 +1,7 @@
class Symbol
- def to_json(options = {}) #:nodoc:
+ def rails_to_json(options = {}) #: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 f45a0059e8..2699672949 100644
--- a/activesupport/lib/active_support/json/encoders/time.rb
+++ b/activesupport/lib/active_support/json/encoders/time.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/time/conversions'
+
class Time
# Returns a JSON string representing the time. If ActiveSupport.use_standard_json_time_format is set to true, the
# ISO 8601 format is used.
@@ -11,11 +13,13 @@ class Time
# # With ActiveSupport.use_standard_json_time_format = false
# Time.utc(2005,2,1,15,15,10).to_json
# # => "2005/02/01 15:15:10 +0000"
- def to_json(options = nil)
+ def rails_to_json(options = nil)
if ActiveSupport.use_standard_json_time_format
xmlschema.inspect
else
%("#{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 037d812b3f..ac7c7d1e87 100644
--- a/activesupport/lib/active_support/json/encoders/true_class.rb
+++ b/activesupport/lib/active_support/json/encoders/true_class.rb
@@ -1,5 +1,7 @@
class TrueClass
- def to_json(options = nil) #:nodoc:
+ 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 aaaa3cdfd2..42a217cedc 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -8,7 +8,7 @@ module ActiveSupport
seen = (options[:seen] ||= [])
raise CircularReferenceError, 'object references itself' if seen.include?(value)
seen << value
- value.send(:to_json, options)
+ value.send(:rails_to_json, options)
ensure
seen.pop
end
diff --git a/activesupport/lib/active_support/json/variable.rb b/activesupport/lib/active_support/json/variable.rb
index 7fd23b0a9e..3ee152ee3c 100644
--- a/activesupport/lib/active_support/json/variable.rb
+++ b/activesupport/lib/active_support/json/variable.rb
@@ -2,7 +2,7 @@ module ActiveSupport
module JSON
# A string that returns itself as its JSON-encoded form.
class Variable < String
- def to_json(options=nil)
+ def rails_to_json(options=nil)
self
end
end
diff --git a/activesupport/lib/active_support/memoizable.rb b/activesupport/lib/active_support/memoizable.rb
index 2b85fd7be4..edf626802a 100644
--- a/activesupport/lib/active_support/memoizable.rb
+++ b/activesupport/lib/active_support/memoizable.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/metaclass'
+
module ActiveSupport
module SafelyMemoizable
def safely_memoize(*symbols)
diff --git a/activesupport/lib/active_support/multibyte.rb b/activesupport/lib/active_support/multibyte.rb
index 65a96af49a..d8d58f3bce 100644
--- a/activesupport/lib/active_support/multibyte.rb
+++ b/activesupport/lib/active_support/multibyte.rb
@@ -4,6 +4,8 @@ require 'active_support/multibyte/chars'
require 'active_support/multibyte/exceptions'
require 'active_support/multibyte/unicode_database'
+require 'active_support/core_ext/module/attribute_accessors'
+
module ActiveSupport #:nodoc:
module Multibyte
# A list of all available normalization forms. See http://www.unicode.org/reports/tr15/tr15-29.html for more
diff --git a/activesupport/lib/active_support/new_callbacks.rb b/activesupport/lib/active_support/new_callbacks.rb
index 356d70b650..7a48dbac04 100644
--- a/activesupport/lib/active_support/new_callbacks.rb
+++ b/activesupport/lib/active_support/new_callbacks.rb
@@ -1,3 +1,6 @@
+require 'active_support/core_ext/array/wrap'
+require 'active_support/core_ext/class/inheritable_attributes'
+
module ActiveSupport
# Callbacks are hooks into the lifecycle of an object that allow you to trigger logic
# before or after an alteration of the object state.
diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb
index ca51adba1e..c529b92240 100644
--- a/activesupport/lib/active_support/testing/assertions.rb
+++ b/activesupport/lib/active_support/testing/assertions.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/array/wrap'
+
module ActiveSupport
module Testing
module Assertions
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index aa448debda..1949ce0ad3 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -130,14 +130,16 @@ module ActiveSupport
# # With ActiveSupport.use_standard_json_time_format = false
# Time.utc(2005,2,1,15,15,10).in_time_zone.to_json
# # => "2005/02/01 15:15:10 +0000"
- def to_json(options = nil)
- if ActiveSupport.use_standard_json_time_format
+ def rails_to_json(options = nil)
+ if !ActiveSupport.respond_to?(:use_standard_json_time_format) || ActiveSupport.use_standard_json_time_format
xmlschema.inspect
else
%("#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}")
end
end
+ alias to_json rails_to_json
+
def to_yaml(options = {})
if options.kind_of?(YAML::Emitter)
utc.to_yaml(options)
diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb
index ccd1349491..f22fbcc0e1 100644
--- a/activesupport/lib/active_support/xml_mini.rb
+++ b/activesupport/lib/active_support/xml_mini.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/module/delegation'
+
module ActiveSupport
# = XmlMini
#
diff --git a/activesupport/lib/active_support/xml_mini/rexml.rb b/activesupport/lib/active_support/xml_mini/rexml.rb
index 771109514c..5033210aae 100644
--- a/activesupport/lib/active_support/xml_mini/rexml.rb
+++ b/activesupport/lib/active_support/xml_mini/rexml.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
# = XmlMini ReXML implementation
module ActiveSupport
module XmlMini_REXML #:nodoc: