Sha256: eb6f2957059cf04caa58fb7e087bf416eed373d7173fcc2ff8d6a19ef5ae341b
Contents?: true
Size: 931 Bytes
Versions: 9
Compression:
Stored size: 931 Bytes
Contents
# frozen_string_literal: true module ActionTracker module Models class Payload < ActionTracker::Models::ApplicationRecord MAX_CONTENT_LENGTH = 1000 attribute :event, String attribute :content, String attribute :user, ActionTracker::Models::User validates :event, :content, presence: true def with_user(user) self[:user] = ActionTracker::Models::User.new( id: user.try(:id), name: user.try(:name), type: user.try(:type) ) self end def user super || ActionTracker::Models::User.default_user end def for_event(event) self[:event] = event.to_s.humanize self end def with_content(content) self[:content] = content.to_s.truncate(MAX_CONTENT_LENGTH) self end def attributes super.merge(user: user.attributes) end end end end
Version data entries
9 entries across 9 versions & 1 rubygems