aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-05-04 19:36:26 +0200
committerXavier Noria <fxn@hashref.com>2010-05-04 19:36:26 +0200
commit583b60d109522907020700225f1c739737297a2d (patch)
treea36d986cbbb73c94d217cbe86c9af7ef97a89567 /activesupport/lib
parent44a98967676492995d19fd4d541dbc9d52bf6b53 (diff)
parent0dd3b4630fea4bd4d4010b7096c9ee79d34c4501 (diff)
downloadrails-583b60d109522907020700225f1c739737297a2d.tar.gz
rails-583b60d109522907020700225f1c739737297a2d.tar.bz2
rails-583b60d109522907020700225f1c739737297a2d.zip
Merge remote branch 'rails/master'
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/cache.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/date/calculations.rb4
-rw-r--r--activesupport/lib/active_support/core_ext/date/conversions.rb1
-rw-r--r--activesupport/lib/active_support/inflector/transliterate.rb5
-rw-r--r--activesupport/lib/active_support/json/encoding.rb9
-rw-r--r--activesupport/lib/active_support/notifications/instrumenter.rb14
6 files changed, 26 insertions, 9 deletions
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
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.
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 = {
diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb
index 5ec87372d0..2344bb1bb3 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 => {
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index e692f6d142..02c233595d 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' # for #to_s
require 'active_support/core_ext/hash/except'
require 'active_support/core_ext/hash/slice'
require 'active_support/core_ext/module/delegation'
@@ -178,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
diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb
index f3d877efe7..7e89402822 100644
--- a/activesupport/lib/active_support/notifications/instrumenter.rb
+++ b/activesupport/lib/active_support/notifications/instrumenter.rb
@@ -12,12 +12,18 @@ 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
- result = yield(payload) if block_given?
- @notifier.publish(name, time, Time.now, @id, payload)
- result
+ begin
+ yield(payload) if block_given?
+ rescue Exception => e
+ payload[:exception] = [e.class.name, e.message]
+ raise e
+ ensure
+ @notifier.publish(name, time, Time.now, @id, payload)
+ end
end
private