Class: Loco::Notification

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/loco/notification.rb,
app/services/loco/notification/fetcher.rb

Defined Under Namespace

Classes: Fetcher

Constant Summary collapse

FOR_OBJ_SQL_TMPL =
'recipient_class = ? AND recipient_id = ?'
FOR_CLASS_SQL_TMPL =
'recipient_class = ? AND recipient_id IS NULL'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#objObject

Returns the value of attribute obj.



8
9
10
# File 'app/models/loco/notification.rb', line 8

def obj
  @obj
end

Class Method Details

.table_name_prefixObject



18
19
20
# File 'app/models/loco/notification.rb', line 18

def table_name_prefix
  'loco_'
end

Instance Method Details

#compactObject



57
58
59
# File 'app/models/loco/notification.rb', line 57

def compact
  [obj_class, obj_id, event, data]
end

#recipient(shallow: false) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'app/models/loco/notification.rb', line 47

def recipient(shallow: false)
  if !recipient_token.nil?
    recipient_token
  elsif regular_recipient?
    init_recipient(shallow)
  elsif !recipient_class.nil?
    recipient_class.constantize
  end
end

#recipient=(val) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/loco/notification.rb', line 33

def recipient=(val)
  return if val.nil?
  return if val == :all

  if val.is_a?(String)
    self.recipient_token = val
  elsif val.instance_of?(Class)
    self.recipient_class = val.to_s
  else
    self.recipient_class = val.class.name
    self.recipient_id = val.id
  end
end