Class: UNotifier::Provider::User::ActionCable

Inherits:
ProviderBase
  • Object
show all
Defined in:
lib/provider/user/action_cable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ProviderBase

#can_notify?

Constructor Details

#initialize(server, channel_name: nil, autohide_delay: 30, notification_conditions: []) ⇒ ActionCable

Returns a new instance of ActionCable.



8
9
10
11
12
13
# File 'lib/provider/user/action_cable.rb', line 8

def initialize(server, channel_name: nil, autohide_delay: 30, notification_conditions: [])
  super(notification_conditions: notification_conditions)
  @server = server
  @channel_name = channel_name
  @autohide_delay = autohide_delay
end

Instance Attribute Details

#autohide_delayObject

Returns the value of attribute autohide_delay.



6
7
8
# File 'lib/provider/user/action_cable.rb', line 6

def autohide_delay
  @autohide_delay
end

#channel_nameObject

Returns the value of attribute channel_name.



6
7
8
# File 'lib/provider/user/action_cable.rb', line 6

def channel_name
  @channel_name
end

#serverObject (readonly)

Returns the value of attribute server.



5
6
7
# File 'lib/provider/user/action_cable.rb', line 5

def server
  @server
end

Instance Method Details

#notify(notification) ⇒ Object



15
16
17
18
19
# File 'lib/provider/user/action_cable.rb', line 15

def notify(notification)
  return unless can_notify?(notification)

  server.broadcast channel_name.call(notification), serialize_notification(notification)
end

#sensitive?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/provider/user/action_cable.rb', line 21

def sensitive?
  false
end

#serialize_notification(notification) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/provider/user/action_cable.rb', line 25

def serialize_notification(notification)
  {
    id: notification.id,
    title: notification.title,
    body: notification.body,
    autohide_delay: notification.autohide_delay || @autohide_delay,
    user_login: notification.target.,
    link: notification.link,
    urgency: notification.urgency,
  }
end