asanghi / fiscali

Fiscal Year Date Functions

Home Page:http://asanghi.github.com/fiscali

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fiscal zone set in initializer but not remembered in app

rshallit opened this issue · comments

My project sets Date.fiscal_zone in an initializer, but the app is acting like Date.fiscal_zone is still nil. Looking at your code, it looks like this is caused by this being stored in the Thread.current hash - the initializer is being run in a different thread than the application itself, and so modifications to the Thread.current hash in the initializer don't carry over.

Here's an example of what's happening - I triggered the debugger at the end of the initializer and in the controller:

=> Rails 3.1.6 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
/Users/sagroup/.rvm/gems/ruby-1.9.2-p290-patched@drachmas/gems/activesupport-3.1.6/lib/active_support/dependencies.rb:641
aborting = false
(rdb:1) pp Date.fiscal_zone
:us
(rdb:1) pp Thread.current[:fiscali_zone]
:us
(rdb:1) pp Thread.current
# <Thread:0x00000109c3b360 run>

(rdb:1) cont
[2012-07-12 11:36:38] INFO  WEBrick 1.3.1
[2012-07-12 11:36:38] INFO  ruby 1.9.2 (2011-07-09) [x86_64-darwin11.3.0]
[2012-07-12 11:36:38] INFO  WEBrick::HTTPServer#start: pid=41940 port=3000
/Users/sagroup/dev/drachmas3/app/controllers/core_dashboard_controller.rb:22
dt = params[:dt] || Date.today.beginning_of_financial_q1
(rdb:2) pp Date.fiscal_zone
nil
(rdb:2) pp Thread.current[:fiscali_zone]
nil
(rdb:2) pp Thread.current
# <Thread:0x0000012ffcd2a0 run>```

Problem fixed in released version 2.1.0 . Sorry about the delay in releasing the gem.