Sha256: 824f51a5f158d9cc0def91d1ec7e293c124011ca1187a24fffa7e2ea8b04a3a3

Contents?: true

Size: 882 Bytes

Versions: 1

Compression:

Stored size: 882 Bytes

Contents

# frozen_string_literal: true

require 'i_am_i_can/subject/role_querying'
require 'i_am_i_can/subject/permission_querying'

module IAmICan
  module Subject
    extend ActiveSupport::Concern

    class_methods do
    end

    included do
      define_model_callbacks :role_assign, :cancel_role_assign, :role_update, :role_none

      Object.const_set (role_assoc_class = reflections[__roles].options[:join_table].camelize),
                       Class.new(ActiveRecord::Base)
      has_many :"assoc_with_#{__roles}", -> { where('expire_at IS NULL OR expire_at > ?', Time.current) },
               class_name: role_assoc_class

      def get_roles(with_tmp: true)
        if with_tmp && (tmp_ids = try(:temporary_roles)&.map(&:id)).present?
          i_am_i_can.role_model.where(id: (tmp_ids + _roles.ids).uniq)
        else
          _roles
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
i_am_i_can-4.4.1 lib/i_am_i_can/subject.rb