lib/resque-bus.rb in resque-bus-0.3.3 vs lib/resque-bus.rb in resque-bus-0.3.4
- old
+ new
@@ -136,12 +136,19 @@
def with_global_attributes(attributes)
original_timezone = false
original_locale = false
- I18n.locale = attributes["bus_locale"] if defined?(I18n) && I18n.respond_to?(:locale=)
- Time.zone = attributes["bus_timezone"] if defined?(Time) && Time.respond_to?(:zone=)
+ if attributes["bus_locale"] && defined?(I18n) && I18n.respond_to?(:locale=)
+ original_locale = I18n.locale if I18n.respond_to?(:locale)
+ I18n.locale = attributes["bus_locale"]
+ end
+ if attributes["bus_timezone"] && defined?(Time) && Time.respond_to?(:zone=)
+ original_timezone = Time.zone if Time.respond_to?(:zone)
+ Time.zone = attributes["bus_timezone"]
+ end
+
yield
ensure
I18n.locale = original_locale unless original_locale == false
Time.zone = original_timezone unless original_timezone == false
end
\ No newline at end of file