Sha256: 715b42fb9c896aaa739c8f9a25f4dc2c45ab6b79b768c3df72d1fcb37535c723

Contents?: true

Size: 819 Bytes

Versions: 24

Compression:

Stored size: 819 Bytes

Contents

class Role < ActiveRecord::Base
  has_and_belongs_to_many :users, join_table: :users_roles
  belongs_to :resource, polymorphic: true

  validates(
    :resource_type,
    inclusion: { in: Rolify.resource_types },
    allow_nil: true
  )

  scopify

  # MessageTrain Gem
  message_train except: :sender,
                valid_senders: :superadmins,
                name_column: :capitalized_name,
                slug_column: :name,
                collectives_for_recipient: :sendable_roles,
                valid_recipients: :recipients

  scope :sendable_roles, (lambda do |_participant|
    where(resource: nil).where.not(name: 'superadmin')
  end)

  def recipients
    User.with_role(name.to_sym)
  end

  def superadmins
    User.with_role(:superadmin)
  end

  def capitalized_name
    name.capitalize
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
message_train-0.7.6 spec/dummy/app/models/role.rb
message_train-0.7.5 spec/dummy/app/models/role.rb
message_train-0.7.3 spec/dummy/app/models/role.rb
message_train-0.7.2 spec/dummy/app/models/role.rb
message_train-0.7.1 spec/dummy/app/models/role.rb
message_train-0.6.17 spec/dummy/app/models/role.rb
message_train-0.6.16 spec/dummy/app/models/role.rb
message_train-0.6.15 spec/dummy/app/models/role.rb
message_train-0.6.14 spec/dummy/app/models/role.rb
message_train-0.6.13 spec/dummy/app/models/role.rb
message_train-0.6.12 spec/dummy/app/models/role.rb
message_train-0.6.11 spec/dummy/app/models/role.rb
message_train-0.6.10 spec/dummy/app/models/role.rb
message_train-0.6.9 spec/dummy/app/models/role.rb
message_train-0.6.8 spec/dummy/app/models/role.rb
message_train-0.6.7 spec/dummy/app/models/role.rb
message_train-0.6.6 spec/dummy/app/models/role.rb
message_train-0.6.5 spec/dummy/app/models/role.rb
message_train-0.6.4 spec/dummy/app/models/role.rb
message_train-0.6.3 spec/dummy/app/models/role.rb