From 7aaabea5175be4b01697684e7573b422629206e6 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 2 May 2010 01:12:31 +0200 Subject: let Date.yesterday and Date.tomorrow be based on Date.current rather than Date.today --- activesupport/lib/active_support/core_ext/date/calculations.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb index 9d2ad2bbcf..fef49e1003 100644 --- a/activesupport/lib/active_support/core_ext/date/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date/calculations.rb @@ -7,12 +7,12 @@ class Date class << self # Returns a new Date representing the date 1 day ago (i.e. yesterday's date). def yesterday - ::Date.today.yesterday + ::Date.current.yesterday end # Returns a new Date representing the date 1 day after today (i.e. tomorrow's date). def tomorrow - ::Date.today.tomorrow + ::Date.current.tomorrow end # Returns Time.zone.today when config.time_zone is set, otherwise just returns Date.today. -- cgit v1.2.3 From 02028e529c97488b6c70cdbf66dc08c7fb2d36aa Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 2 May 2010 14:59:51 -0300 Subject: Missing require added make pass activesupport/test/json/encoding_test.rb in isolation Signed-off-by: Xavier Noria --- activesupport/lib/active_support/json/encoding.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index e692f6d142..3d7be8da1f 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -1,6 +1,7 @@ # encoding: utf-8 require 'bigdecimal' require 'active_support/core_ext/array/wrap' +require 'active_support/core_ext/big_decimal/conversions' require 'active_support/core_ext/hash/except' require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/module/delegation' -- cgit v1.2.3 From 109d3ee38d1c39f0e27bc827065427635d6396b2 Mon Sep 17 00:00:00 2001 From: Justin George Date: Tue, 27 Apr 2010 14:13:47 -0700 Subject: Make notifications go off even when an error is raised, so that we capture the underlying performance data [#4505 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is important when trying to keep track of many layers of interrelated calls i.e.: ActiveRecord::Base.transaction do MyModel.find(1) #ActiveRecord::NotFound end # should capture the full time until the error propagation Signed-off-by: José Valim --- activesupport/lib/active_support/notifications/instrumenter.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index f3d877efe7..ef3fdd1843 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -15,9 +15,13 @@ module ActiveSupport # and publish it. def instrument(name, payload={}) time = Time.now - result = yield(payload) if block_given? - @notifier.publish(name, time, Time.now, @id, payload) - result + begin + yield(payload) if block_given? + ensure + # Notify in an ensure block so that we can be certain end + # events get sent even if an error occurs in the passed-in block + @notifier.publish(name, time, Time.now, @id, payload) + end end private -- cgit v1.2.3 From 731d4392e478ff5526b595074d9caa999da8bd0c Mon Sep 17 00:00:00 2001 From: Justin George Date: Tue, 27 Apr 2010 21:16:06 -0700 Subject: Change event namespace ordering to most-significant first [#4504 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More work still needs to be done on some of these names (render_template.action_view and render_template!.action_view particularly) but this allows (for example) /^sql/ to subscribe to all the various ORMs without further modification Signed-off-by: José Valim --- 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 ec5007c284..2605a3f2b8 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -502,7 +502,7 @@ module ActiveSupport if self.class.instrument payload = { :key => key } payload.merge!(options) if options.is_a?(Hash) - ActiveSupport::Notifications.instrument("active_support.cache_#{operation}", payload){ yield } + ActiveSupport::Notifications.instrument("cache_#{operation}.active_support", payload){ yield } else yield end -- cgit v1.2.3 From a76c7e68d5e39f5962d9cb85c98e6a8e96f8b3af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 2 May 2010 22:40:20 +0200 Subject: Event should be aware if yielded block failed or not. --- activesupport/lib/active_support/notifications/instrumenter.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index ef3fdd1843..7e89402822 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -12,14 +12,16 @@ module ActiveSupport end # Instrument the given block by measuring the time taken to execute it - # and publish it. + # and publish it. Notice that events get sent even if an error occurs + # in the passed-in block def instrument(name, payload={}) time = Time.now begin yield(payload) if block_given? + rescue Exception => e + payload[:exception] = [e.class.name, e.message] + raise e ensure - # Notify in an ensure block so that we can be certain end - # events get sent even if an error occurs in the passed-in block @notifier.publish(name, time, Time.now, @id, payload) end end -- cgit v1.2.3 From 756f762cdb1ee5ad0046e40e3620399d1707fee7 Mon Sep 17 00:00:00 2001 From: Norman Clarke Date: Mon, 3 May 2010 10:16:38 -0300 Subject: Fix transliteration rule example in docs. [#4526 state:resolved] Signed-off-by: Xavier Noria --- activesupport/lib/active_support/inflector/transliterate.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb index 5ec87372d0..2c9115c427 100644 --- a/activesupport/lib/active_support/inflector/transliterate.rb +++ b/activesupport/lib/active_support/inflector/transliterate.rb @@ -24,8 +24,9 @@ module ActiveSupport # # Store the transliterations in locales/de.yml # i18n: # transliterate: - # ü: "ue" - # ö: "oe" + # :rule + # ü: "ue" + # ö: "oe" # # # Or set them using Ruby # I18n.backend.store_translations(:de, :i18n => { -- cgit v1.2.3 From 34d57251672d31e70d3ce53e1df3ea9dd4aae9c8 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 3 May 2010 15:25:28 +0200 Subject: fixes colon in previous YAML example --- activesupport/lib/active_support/inflector/transliterate.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb index 2c9115c427..2344bb1bb3 100644 --- a/activesupport/lib/active_support/inflector/transliterate.rb +++ b/activesupport/lib/active_support/inflector/transliterate.rb @@ -24,7 +24,7 @@ module ActiveSupport # # Store the transliterations in locales/de.yml # i18n: # transliterate: - # :rule + # rule: # ü: "ue" # ö: "oe" # -- cgit v1.2.3 From 9e085a9f3365e316e2026addedef30f08ead46f2 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 3 May 2010 22:04:47 +0200 Subject: adds a comment explaining why BigDecimal#as_json returns a JSON string --- activesupport/lib/active_support/json/encoding.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 3d7be8da1f..02c233595d 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -1,7 +1,7 @@ # encoding: utf-8 require 'bigdecimal' require 'active_support/core_ext/array/wrap' -require 'active_support/core_ext/big_decimal/conversions' +require 'active_support/core_ext/big_decimal/conversions' # for #to_s require 'active_support/core_ext/hash/except' require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/module/delegation' @@ -179,6 +179,14 @@ class Numeric end class BigDecimal + # A BigDecimal would be naturally represented as a JSON number. Most libraries, + # however, parse non-integer JSON numbers directly as floats. Clients using + # those libraries would get in general a wrong number and no way to recover + # other than manually inspecting the string with the JSON code itself. + # + # That's why a JSON string is returned. The JSON literal is not numeric, but if + # the other end knows by contract that the data is supposed to be a BigDecimal, + # it still has the chance to post-process the string and get the real value. def as_json(options = nil) to_s end #:nodoc: end -- cgit v1.2.3 From 6704d8c994d9d20d0cc9d71b72521e141c7dc05d Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 3 May 2010 23:11:09 +0200 Subject: date/conversions needs time/calculations for (utc|local)_time --- activesupport/lib/active_support/core_ext/date/conversions.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb index 90ab1eb281..13ef703f49 100644 --- a/activesupport/lib/active_support/core_ext/date/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date/conversions.rb @@ -1,5 +1,6 @@ require 'date' require 'active_support/inflector' +require 'active_support/core_ext/time/calculations' class Date DATE_FORMATS = { -- cgit v1.2.3