Class: Biovision::Notifiers::BaseNotifier
- Inherits:
-
Object
- Object
- Biovision::Notifiers::BaseNotifier
show all
- Defined in:
- app/lib/biovision/notifiers/base_notifier.rb
Overview
Base notifier class for dispatching component notifications
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of BaseNotifier.
10
11
12
|
# File 'app/lib/biovision/notifiers/base_notifier.rb', line 10
def initialize(user)
@user = user
end
|
Instance Attribute Details
#notification ⇒ Object
Returns the value of attribute notification.
7
8
9
|
# File 'app/lib/biovision/notifiers/base_notifier.rb', line 7
def notification
@notification
end
|
#user ⇒ Object
Returns the value of attribute user.
7
8
9
|
# File 'app/lib/biovision/notifiers/base_notifier.rb', line 7
def user
@user
end
|
Class Method Details
.[](notification) ⇒ Object
15
16
17
18
19
20
|
# File 'app/lib/biovision/notifiers/base_notifier.rb', line 15
def self.[](notification)
slug = notification.component_slug
instance = handler_class(slug).new(notification.user)
instance.notification = notification
instance
end
|
.handler_class(slug) ⇒ Object
27
28
29
30
|
# File 'app/lib/biovision/notifiers/base_notifier.rb', line 27
def self.handler_class(slug)
handler_name = "biovision/notifiers/#{slug}_notifier".classify
handler_name.safe_constantize || BaseNotifier
end
|
.slug ⇒ Object
22
23
24
|
# File 'app/lib/biovision/notifiers/base_notifier.rb', line 22
def self.slug
to_s.demodulize.to_s.underscore.gsub('_notifier', '')
end
|
Instance Method Details
#component ⇒ Object
32
33
34
|
# File 'app/lib/biovision/notifiers/base_notifier.rb', line 32
def component
@component ||= BiovisionComponent[self.class.slug]
end
|
#entity ⇒ Object
36
37
38
|
# File 'app/lib/biovision/notifiers/base_notifier.rb', line 36
def entity
nil
end
|
#notify(data) ⇒ Object
47
48
49
50
|
# File 'app/lib/biovision/notifiers/base_notifier.rb', line 47
def notify(data)
attributes = { user: user, biovision_component: component, data: data }
Notification.create(attributes)
end
|
#view ⇒ Object
40
41
42
43
44
|
# File 'app/lib/biovision/notifiers/base_notifier.rb', line 40
def view
return if notification.nil?
"my/notifications/#{self.class.slug}/#{notification.data['type']}"
end
|