Skip to content

Instantly share code, notes, and snippets.

@Tocacar
Created June 28, 2019 13:58
Show Gist options
  • Save Tocacar/f6b81c52aa770efecd1339726b48e3f8 to your computer and use it in GitHub Desktop.
Save Tocacar/f6b81c52aa770efecd1339726b48e3f8 to your computer and use it in GitHub Desktop.
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