Sha256: eb28311fdd7be25b87a6fe839e2508cf65bf3a5e12041d631633398c7568ce45

Contents?: true

Size: 790 Bytes

Versions: 11

Compression:

Stored size: 790 Bytes

Contents

# frozen_string_literal: true
module Monarchy
  module ActsAsRole
    extend ActiveSupport::Concern

    module ClassMethods
      def acts_as_role
        self.table_name = 'monarchy_roles'

        has_many :members_roles, dependent: :destroy, class_name: 'Monarchy::MembersRole'
        has_many :members, through: :members_roles, class_name: "::#{Monarchy.member_class}"

        belongs_to :inherited_role, class_name: "::#{Monarchy.role_class}"

        after_create :default_inherited_role

        include Monarchy::ActsAsRole::InstanceMethods
      end
    end

    module InstanceMethods
      private

      def default_inherited_role
        update(inherited_role_id: id) unless inherited_role
      end
    end
  end
end

ActiveRecord::Base.send :include, Monarchy::ActsAsRole

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
monarchy-2.1.0 lib/monarchy/acts_as_role.rb
monarchy-2.0.8 lib/monarchy/acts_as_role.rb
monarchy-2.0.7 lib/monarchy/acts_as_role.rb
monarchy-2.0.6 lib/monarchy/acts_as_role.rb
monarchy-2.0.5 lib/monarchy/acts_as_role.rb
monarchy-2.0.4 lib/monarchy/acts_as_role.rb
monarchy-2.0.0.pre.beta.1 lib/monarchy/acts_as_role.rb
monarchy-1.1.5 lib/monarchy/acts_as_role.rb
monarchy-1.1.4 lib/monarchy/acts_as_role.rb
monarchy-1.1.3 lib/monarchy/acts_as_role.rb
monarchy-1.0.0 lib/monarchy/acts_as_role.rb