aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support.rb2
-rw-r--r--activesupport/lib/active_support/cache.rb4
-rw-r--r--activesupport/lib/active_support/core_ext/float/rounding.rb5
-rw-r--r--activesupport/lib/active_support/deprecation/behaviors.rb2
-rw-r--r--activesupport/lib/active_support/duration.rb6
-rw-r--r--activesupport/lib/active_support/json/encoding.rb3
-rw-r--r--activesupport/lib/active_support/notifications.rb14
-rw-r--r--activesupport/lib/active_support/notifications/instrumenter.rb8
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb7
9 files changed, 29 insertions, 22 deletions
diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb
index 3463000529..51ec87f329 100644
--- a/activesupport/lib/active_support.rb
+++ b/activesupport/lib/active_support.rb
@@ -66,6 +66,8 @@ module ActiveSupport
autoload :StringInquirer
autoload :XmlMini
end
+
+ autoload :TestCase
end
require 'active_support/vendor'
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb
index ad238c1d96..6360a4614e 100644
--- a/activesupport/lib/active_support/cache.rb
+++ b/activesupport/lib/active_support/cache.rb
@@ -247,13 +247,13 @@ module ActiveSupport
expires_in || 0
end
- def instrument(operation, key, options, &block)
+ def instrument(operation, key, options)
log(operation, key, options)
if self.class.instrument
payload = { :key => key }
payload.merge!(options) if options.is_a?(Hash)
- ActiveSupport::Notifications.instrument(:"cache_#{operation}", payload, &block)
+ ActiveSupport::Notifications.instrument("active_support.cache_#{operation}", payload){ yield }
else
yield
end
diff --git a/activesupport/lib/active_support/core_ext/float/rounding.rb b/activesupport/lib/active_support/core_ext/float/rounding.rb
index 0b1ae4be7e..9bdf5bba7b 100644
--- a/activesupport/lib/active_support/core_ext/float/rounding.rb
+++ b/activesupport/lib/active_support/core_ext/float/rounding.rb
@@ -1,5 +1,6 @@
class Float
- remove_method :round
+ alias precisionless_round round
+ private :precisionless_round
# Rounds the float with the specified precision.
#
@@ -12,7 +13,7 @@ class Float
magnitude = 10.0 ** precision
(self * magnitude).round / magnitude
else
- super()
+ precisionless_round
end
end
end
diff --git a/activesupport/lib/active_support/deprecation/behaviors.rb b/activesupport/lib/active_support/deprecation/behaviors.rb
index ca23d45666..578c025fcf 100644
--- a/activesupport/lib/active_support/deprecation/behaviors.rb
+++ b/activesupport/lib/active_support/deprecation/behaviors.rb
@@ -12,7 +12,7 @@ module ActiveSupport
end
def default_behavior
- Deprecation::DEFAULT_BEHAVIORS[defined?(Rails) ? Rails.env.to_s : 'test']
+ Deprecation::DEFAULT_BEHAVIORS[defined?(Rails.env) ? Rails.env.to_s : 'test']
end
end
diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb
index c1f0e4bf81..db5afb5324 100644
--- a/activesupport/lib/active_support/duration.rb
+++ b/activesupport/lib/active_support/duration.rb
@@ -36,7 +36,7 @@ module ActiveSupport
end
def is_a?(klass) #:nodoc:
- klass == Duration || super
+ Duration == klass || value.is_a?(klass)
end
# Returns true if <tt>other</tt> is also a Duration instance with the
@@ -50,7 +50,9 @@ module ActiveSupport
end
def self.===(other) #:nodoc:
- other.is_a?(Duration) rescue super
+ other.is_a?(Duration)
+ rescue ::NoMethodError
+ false
end
# Calculates a new Time or Date that is as far in the future
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index c8415d5449..8ba45f7ea2 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -114,7 +114,8 @@ module ActiveSupport
end
end
- self.escape_html_entities_in_json = true
+ self.use_standard_json_time_format = true
+ self.escape_html_entities_in_json = false
end
CircularReferenceError = Deprecation::DeprecatedConstantProxy.new('ActiveSupport::JSON::CircularReferenceError', Encoding::CircularReferenceError)
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb
index d9bfcbfcab..3e96decb8c 100644
--- a/activesupport/lib/active_support/notifications.rb
+++ b/activesupport/lib/active_support/notifications.rb
@@ -44,11 +44,16 @@ module ActiveSupport
class << self
attr_writer :notifier
- delegate :publish, :subscribe, :instrument, :to => :notifier
+ delegate :publish, :subscribe, :to => :notifier
+ delegate :instrument, :to => :instrumenter
def notifier
@notifier ||= Notifier.new
end
+
+ def instrumenter
+ Thread.current[:"instrumentation_#{notifier.object_id}"] ||= Instrumenter.new(notifier)
+ end
end
class Notifier
@@ -67,13 +72,6 @@ module ActiveSupport
def wait
@queue.wait
end
-
- delegate :instrument, :to => :current_instrumenter
-
- private
- def current_instrumenter
- Thread.current[:"instrumentation_#{object_id}"] ||= Notifications::Instrumenter.new(self)
- end
end
end
end
diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb
index 0655dd0cb6..f3d877efe7 100644
--- a/activesupport/lib/active_support/notifications/instrumenter.rb
+++ b/activesupport/lib/active_support/notifications/instrumenter.rb
@@ -4,16 +4,20 @@ require 'active_support/core_ext/module/delegation'
module ActiveSupport
module Notifications
class Instrumenter
+ attr_reader :id
+
def initialize(notifier)
@id = unique_id
@notifier = notifier
end
+ # Instrument the given block by measuring the time taken to execute it
+ # and publish it.
def instrument(name, payload={})
time = Time.now
- yield if block_given?
- ensure
+ result = yield(payload) if block_given?
@notifier.publish(name, time, Time.now, @id, payload)
+ result
end
private
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index 6b554e7158..710dce78de 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -32,7 +32,6 @@ module ActiveSupport
# t.is_a?(Time) # => true
# t.is_a?(ActiveSupport::TimeWithZone) # => true
class TimeWithZone
-
def self.name
'Time' # Report class name as 'Time' to thwart type checking
end
@@ -114,9 +113,9 @@ module ActiveSupport
end
alias_method :iso8601, :xmlschema
- # Coerces the date to a string for JSON encoding.
- #
- # ISO 8601 format is used if ActiveSupport::JSON::Encoding.use_standard_json_time_format is set.
+ # Coerces the date to a string for JSON encoding. The default format is ISO 8601. You can get
+ # %Y/%m/%d %H:%M:%S +offset style by setting ActiveSupport::JSON::Encoding.use_standard_json_time_format
+ # to false.
#
# ==== Examples
#