1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/models/account_role.rb

41 lines
713 B
Ruby
Raw Normal View History

2019-02-01 22:48:23 -05:00
# frozen_string_literal: true
class AccountRole < ApplicationRecord
2019-03-25 20:56:31 -04:00
################
# Associations #
################
2019-02-01 22:48:23 -05:00
belongs_to :account
belongs_to :role
2019-02-01 23:35:08 -05:00
2019-03-25 20:56:31 -04:00
##########
# Scopes #
##########
2019-02-08 01:42:32 -05:00
scope :active, -> { not_deleted.not_expired }
scope :not_deleted, -> { where(deleted_at: nil) }
scope :not_expired, lambda {
where(
arel_table[:expires_at].eq(nil).or(
arel_table[:expires_at].gt(Time.zone.now),
),
)
}
2019-02-01 23:42:35 -05:00
2019-03-25 20:56:31 -04:00
###############
# Validations #
###############
2019-02-01 23:42:35 -05:00
validate :deleted_at_is_not_in_future
private
def deleted_at_is_not_in_future
return if deleted_at.nil?
errors.add :deleted_at unless deleted_at <= Time.zone.now + 10
end
2019-02-01 22:48:23 -05:00
end