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/role.rb
2019-02-02 07:35:58 +05:00

29 lines
596 B
Ruby

# frozen_string_literal: true
class Role < ApplicationRecord
NAMES = %w[
superuser
].map(&:freeze).freeze
has_and_belongs_to_many :accounts, join_table: :account_roles
belongs_to :resource, polymorphic: true, optional: true
validates :name,
presence: true,
inclusion: { in: NAMES }
validates :resource_type,
allow_nil: true,
inclusion: { in: Rolify.resource_types }
scopify
def human_name
I18n.translate name, scope: :roles
end
def human_resource
"#{resource_type} ##{resource_id}" if resource_id
end
end