Class: ActionTracker::Models::Payload

Inherits:
ApplicationRecord show all
Defined in:
lib/action_tracker/models/payload.rb

Constant Summary collapse

MAX_CONTENT_LENGTH =
1000

Instance Method Summary collapse

Methods inherited from ApplicationRecord

infer_model_name, mimic, mimicked_model_name, model_name, #model_name, #to_key

Instance Method Details

#for_event(event) ⇒ Object



24
25
26
27
# File 'lib/action_tracker/models/payload.rb', line 24

def for_event(event)
  self[:event] = event.to_s.humanize
  self
end

#with_content(content) ⇒ Object



29
30
31
32
# File 'lib/action_tracker/models/payload.rb', line 29

def with_content(content)
  self[:content] = content.to_s.truncate(MAX_CONTENT_LENGTH)
  self
end

#with_user(user) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/action_tracker/models/payload.rb', line 14

def with_user(user)
  self[:user] = ActionTracker::Models::User.new(
    id: user.try(:id),
    name: user.try(:name),
    type: user.try(:type)
  )

  self
end