mirror of
https://github.com/Growstuff/growstuff.git
synced 2025-12-24 01:57:46 -05:00
20 lines
440 B
Ruby
20 lines
440 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Role < ApplicationRecord
|
|
extend FriendlyId
|
|
|
|
friendly_id :name, use: %i(slugged finders)
|
|
validates :name, uniqueness: true, presence: true
|
|
|
|
has_and_belongs_to_many :members
|
|
|
|
class << self
|
|
%i(crop_wranglers admins).each do |method|
|
|
define_method method do
|
|
slug = method.to_s.singularize.dasherize
|
|
Role.where(slug:).try(:first).try(:members)
|
|
end
|
|
end
|
|
end
|
|
end
|