mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 14:31:25 +00:00
20 lines
434 B
Ruby
20 lines
434 B
Ruby
module AutoSync
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
before_action :sync_family, if: :family_needs_auto_sync?
|
|
end
|
|
|
|
private
|
|
def sync_family
|
|
Current.family.sync_later
|
|
end
|
|
|
|
def family_needs_auto_sync?
|
|
return false unless Current.family.present?
|
|
return false unless Current.family.accounts.active.any?
|
|
|
|
(Current.family.last_synced_at&.to_date || 1.day.ago) < Date.current
|
|
end
|
|
end
|