1class Holiday < ActiveRecord::Base |
|
2 class << self |
|
3 def before_remove_const |
|
4 Thread.current[:__holiday__] = nil |
|
5 end |
|
7 def instance |
|
8 Thread.current[:__holiday__] ||= first_or_create(defaults) |
|
9 end |
|
11 def christmas?(today = Date.current) |
|
12 instance.christmas?(today)
|
|
13 end |
|
15 def easter?(today = Date.current) |
|
16 instance.easter?(today)
|
|
17 end |
|
19 private
|
|
21 def defaults |
|
22 {
|
|
23 christmas_start: '2017-12-22', |
|
24 christmas_end: '2018-01-04', |
|
25 easter_start: '2018-03-30', |
|
26 easter_end: '2018-04-09' |
|
27 }
|
|
28 end |
|
29 end |
|
|
31 def christmas?(today = Date.current) |
32 christmas.cover?(today)
|
|
33 end |
|
|
35 def easter?(today = Date.current) |
36 easter.cover?(today)
|
|
37 end |
|
39 private
|
|
|
41 def christmas |
42 christmas_start..christmas_end
|
|
43 end |
|
|
45 def easter |
46 easter_start..easter_end
|
|
47 end |
|
48end |