# app/models/account.rb
class Account < ActiveRecord::Base
has_many :connections, dependent: :destroy
has_many :orders, class_name: 'Purchase::Order'
before_create do
self.auth_id = SecureRandom.uuid
self.auth_token = SecureRandom.hex
end
def already_connected_with?(provider)
connections.find_by(provider: provider).present?
end
def overwrite_connection(provider:, provider_uid:)
connections.find_by!(provider: provider).update!(provider_uid: provider_uid)
end
def register_birth_date(year, month)
update!(birth_date: build_birth_date(year, month))
end
def child?
become_adult_day.future?
end
private
def become_adult_day
birth_date + 20.years + 1.month
end