Sha256: 86a0349dbc6eb3383a37a220c9acae659ab28a2323f1803b60ea710c69b85883

Contents?: true

Size: 658 Bytes

Versions: 24

Compression:

Stored size: 658 Bytes

Contents

module Challah
  module UserAuthorizable
    extend ActiveSupport::Concern

    included do
      extend ClassMethods

      before_destroy :clear_authorizations_before_destroy
    end

    protected

    def authorizations
      return [] if new_record?
      self.class.authorization_model.where(user_id: self.id)
    end

    def clear_authorizations_before_destroy
      authorizations.destroy_all
    end

    module ClassMethods
      def authorizations_table_name
        @authorizations_table_name ||= authorization_model.table_name
      end

      def authorization_model
        @authorization_model ||= ::Authorization
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
challah-1.2.2 lib/challah/concerns/user/authorizable.rb
challah-1.2.1 lib/challah/concerns/user/authorizable.rb
challah-1.2.0 lib/challah/concerns/user/authorizable.rb
challah-1.2.0.rc lib/challah/concerns/user/authorizable.rb