From 6fbe9ef2ffb1858027130789246f3ae24a0a182f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 3 Jan 2010 20:39:42 +0100 Subject: Use namespaces in notifications. --- activesupport/lib/active_support/cache.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index ad238c1d96..25314ffd43 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("activesupport.cache_#{operation}", payload){ yield } else yield end -- cgit v1.2.3 From 3990310a2bedd0dff5753e3e9b1282e686cff0cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 4 Jan 2010 00:03:56 +0100 Subject: Use underscore in notification namespaces. --- activesupport/lib/active_support/cache.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 25314ffd43..6360a4614e 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -253,7 +253,7 @@ module ActiveSupport if self.class.instrument payload = { :key => key } payload.merge!(options) if options.is_a?(Hash) - ActiveSupport::Notifications.instrument("activesupport.cache_#{operation}", payload){ yield } + ActiveSupport::Notifications.instrument("active_support.cache_#{operation}", payload){ yield } else yield end -- cgit v1.2.3 From 6042067c0b20602e72954450e9e8a19dfa8a9f7d Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 3 Jan 2010 19:20:43 -0800 Subject: Changed the default ActiveSupport.use_standard_json_time_format from false to true and ActiveSupport.escape_html_entities_in_json from true to false to match previously announced Rails 3 defaults [DHH] --- activesupport/lib/active_support/json/encoding.rb | 3 ++- activesupport/lib/active_support/time_with_zone.rb | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'activesupport/lib') 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/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 # -- cgit v1.2.3 From 45462c5e41a77e600878f7b8b2e41babeef8fe8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 4 Jan 2010 22:22:21 +0100 Subject: Expose Instrumenter id in Notifications. --- activesupport/lib/active_support/notifications/instrumenter.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 0655dd0cb6..3b0b0d8da2 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -4,6 +4,8 @@ require 'active_support/core_ext/module/delegation' module ActiveSupport module Notifications class Instrumenter + attr_reader :id + def initialize(notifier) @id = unique_id @notifier = notifier -- cgit v1.2.3 From 2601a16ede92566c651c06942294250ea653bd85 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 4 Jan 2010 16:22:39 -0600 Subject: Autoload AS test case --- activesupport/lib/active_support.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activesupport/lib') 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' -- cgit v1.2.3 From 74f6ccea201d778e020f8c758013d90ea8a5c8a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 6 Jan 2010 22:23:29 +0100 Subject: instrumenter should be accessible from ActiveSupport::Notifications. --- activesupport/lib/active_support/notifications.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'activesupport/lib') 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 -- cgit v1.2.3 From 816ba1e15a709337a99a931e80dddfe5bf972de5 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 6 Jan 2010 23:34:40 -0800 Subject: Remove unneeded reliance on Numeric#round quirk --- activesupport/lib/active_support/core_ext/float/rounding.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') 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 -- cgit v1.2.3 From a323b83acfe6e02812ec3b7b4ce912b07c85220e Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 7 Jan 2010 00:05:06 -0800 Subject: Remove unneeded reliance on super -> method_missing quirk --- activesupport/lib/active_support/duration.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index c1f0e4bf81..887a40d35e 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 other 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 -- cgit v1.2.3 From ee85f154534b3e511de810050dd4513402c16a28 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 7 Jan 2010 16:43:25 -0800 Subject: Qualify constant lookup in BasicObject --- activesupport/lib/active_support/duration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index 887a40d35e..db5afb5324 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -51,7 +51,7 @@ module ActiveSupport def self.===(other) #:nodoc: other.is_a?(Duration) - rescue NoMethodError + rescue ::NoMethodError false end -- cgit v1.2.3 From 4704af763f47362135b644302b8666e36a58fb34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 12 Jan 2010 13:07:04 +0100 Subject: Do not send notifications when instrumentation raise an error. --- activesupport/lib/active_support/notifications/instrumenter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 3b0b0d8da2..af35eb92cb 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -13,9 +13,9 @@ module ActiveSupport def instrument(name, payload={}) time = Time.now - yield if block_given? - ensure + result = yield if block_given? @notifier.publish(name, time, Time.now, @id, payload) + result end private -- cgit v1.2.3 From da5978c22374b8a3b15a421ff4920e0940435253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 13 Jan 2010 00:41:04 +0100 Subject: Add subscriber for ActionPack and move all logging inside it. --- activesupport/lib/active_support/deprecation/behaviors.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') 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 -- cgit v1.2.3 From 7c3573f32757e9c4c6b6140499a3e7dfe2d335b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 13 Jan 2010 22:28:18 +0100 Subject: Add instrument! to notifications which adds the result to the payload. --- activesupport/lib/active_support/notifications.rb | 2 +- activesupport/lib/active_support/notifications/instrumenter.rb | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 3e96decb8c..a1383bb478 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -45,7 +45,7 @@ module ActiveSupport class << self attr_writer :notifier delegate :publish, :subscribe, :to => :notifier - delegate :instrument, :to => :instrumenter + delegate :instrument, :instrument!, :to => :instrumenter def notifier @notifier ||= Notifier.new diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index af35eb92cb..85c5199946 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -11,13 +11,21 @@ module ActiveSupport @notifier = notifier end - def instrument(name, payload={}) + # Instrument the given block by measuring the time taken to execute it + # and publish it. + def instrument(name, payload={}, add_result=false) time = Time.now result = yield if block_given? + payload.merge!(:result => result) if add_result @notifier.publish(name, time, Time.now, @id, payload) result end + # The same as instrument, but adds the result as payload. + def instrument!(name, payload={}, &block) + instrument(name, payload, true, &block) + end + private def unique_id SecureRandom.hex(10) -- cgit v1.2.3 From 7f4d8e3fbd704cf1005a46309e3795192b114013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 15 Jan 2010 11:01:37 +0100 Subject: Yield the payload notifications for further modification (like adding the result). --- activesupport/lib/active_support/notifications.rb | 2 +- activesupport/lib/active_support/notifications/instrumenter.rb | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index a1383bb478..3e96decb8c 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -45,7 +45,7 @@ module ActiveSupport class << self attr_writer :notifier delegate :publish, :subscribe, :to => :notifier - delegate :instrument, :instrument!, :to => :instrumenter + delegate :instrument, :to => :instrumenter def notifier @notifier ||= Notifier.new diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 85c5199946..f3d877efe7 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -13,19 +13,13 @@ module ActiveSupport # Instrument the given block by measuring the time taken to execute it # and publish it. - def instrument(name, payload={}, add_result=false) + def instrument(name, payload={}) time = Time.now - result = yield if block_given? - payload.merge!(:result => result) if add_result + result = yield(payload) if block_given? @notifier.publish(name, time, Time.now, @id, payload) result end - # The same as instrument, but adds the result as payload. - def instrument!(name, payload={}, &block) - instrument(name, payload, true, &block) - end - private def unique_id SecureRandom.hex(10) -- cgit v1.2.3