We load definitions into memory only when they are referenced or in certain specific cross-loading scenarios. This could lead to a scenario where running a single region returns slightly different results.
That said, even if the results are slightly different they should still be correct in the sense that the user sees what they expect for a specific query.
Here is an example:
~/Code/ppeble/holidays(master ✗) make console
bundle exec rake console
irb -r rubygems -I lib -r holidays.rb
irb(main):001:0> d = Date.civil(2014, 6, 23)
=> #<Date: 2014-06-23 ((2456832j,0s,0n),+0s,2299161j)>
irb(main):002:0> Holidays::Factory::Definition.regions_repository.all_loaded
=> []
irb(main):003:0> Holidays.on(d, :co)
=> [{:date=>#<Date: 2014-06-23 ((2456832j,0s,0n),+0s,2299161j)>, :name=>"Corpus Christi", :regions=>[:co]}]
irb(main):004:0> Holidays::Factory::Definition.regions_repository.all_loaded
=> [:co]
irb(main):005:0> Holidays.on(d, :br)
=> [{:date=>#<Date: 2014-06-23 ((2456832j,0s,0n),+0s,2299161j)>, :name=>"Corpus Christi", :regions=>[:co, :br]}]
irb(main):006:0> Holidays::Factory::Definition.regions_repository.all_loaded
=> [:co, :br]
irb(main):007:0> Holidays.on(d, :co)
=> [{:date=>#<Date: 2014-06-23 ((2456832j,0s,0n),+0s,2299161j)>, :name=>"Corpus Christi", :regions=>[:co, :br]}]
You can see that on the first call it returns this:
[{:date=>#<Date: 2014-06-23 ((2456832j,0s,0n),+0s,2299161j)>, :name=>"Corpus Christi", :regions=>[:co]}]
And then on the last call it returns this:
[{:date=>#<Date: 2014-06-23 ((2456832j,0s,0n),+0s,2299161j)>, :name=>"Corpus Christi", :regions=>[:co, :br]}]
This is because on the first call we have not loaded the br
definitions. Once we make a specific all for br
we will then see it reported in the regions
for this specific holiday.
But again, this is still 'correct'. The user didn't ask for br
holidays in the first call so not including them is still accurate. Adding them in the last response is also correct now that the definitions are loaded.