Created
June 28, 2019 13:58
-
-
Save Tocacar/f6b81c52aa770efecd1339726b48e3f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BankHoliday < ApplicationRecord | |
serialize :dates, Array | |
scope :by_updated_at, -> { order(updated_at: :asc) } | |
before_validation :populate_dates | |
validates :dates, presence: true | |
def self.dates | |
BankHolidayUpdateWorker.perform_in 10.seconds | |
instance = by_updated_at.last || create! | |
instance.dates | |
end | |
def populate_dates | |
self.dates = BankHolidayRetriever.dates unless dates.present? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment