Sha256: 44c0c608d6e2dc729ce7c2e9ce45c7df1f7d619e6189880dcc55ceb73b170c8c

Contents?: true

Size: 821 Bytes

Versions: 2

Compression:

Stored size: 821 Bytes

Contents

module Cas
  class Activity < ApplicationRecord
    belongs_to :site
    belongs_to :user, optional: true
    belongs_to :subject, polymorphic: true

    # To prevent losing data in case the subject is ever destroyed
    before_validation :cache_description

    private

    def cache_description
      if self.user_description.blank?
        user_string = [user.name]
        user_string << ["(admin)"] if user.admin?
        self.user_description = user_string.join(" ")
      end

      if self.subject_description.blank?
        subject_string = []
        if subject.respond_to?(:title)
          subject_string << [subject.title]
        elsif subject.respond_to?(:name)
          subject_string << [subject.name]
        end
        self.subject_description = subject_string.join(" ")
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cas-cms-1.0.0.alpha2 app/models/cas/activity.rb
cas-cms-1.0.0.alpha1 app/models/cas/activity.rb