Class: Integral::Notification::NotificationDecorator
- Inherits:
-
Draper::Decorator
- Object
- Draper::Decorator
- Integral::Notification::NotificationDecorator
- Defined in:
- app/decorators/integral/notification/notification_decorator.rb
Instance Method Summary collapse
- #action_verb ⇒ Object
-
#decorated_item ⇒ Object
Associated Item.
- #formatted_action ⇒ Object
- #item ⇒ Object
- #item_klass ⇒ Object
-
#item_title ⇒ String
Formatted title.
-
#item_url ⇒ String
Item URL.
-
#model_name ⇒ String
Formatted item type.
-
#whodunnit ⇒ Integral::User
Who carried out the version (if one exists).
-
#whodunnit_avatar_url ⇒ String
Image linked to whodunnit.
-
#whodunnit_name ⇒ String
Name linked to whodunnit.
- #whodunnit_url ⇒ Object
Instance Method Details
#action_verb ⇒ Object
10 11 12 |
# File 'app/decorators/integral/notification/notification_decorator.rb', line 10 def action_verb h.t("integral.actions.tense.past.#{object.action}") end |
#decorated_item ⇒ Object
Returns Associated Item.
60 61 62 |
# File 'app/decorators/integral/notification/notification_decorator.rb', line 60 def decorated_item @decorated_item ||= item&.decorate end |
#formatted_action ⇒ Object
6 7 8 |
# File 'app/decorators/integral/notification/notification_decorator.rb', line 6 def formatted_action h.t("integral.actions.#{object.action}") end |
#item ⇒ Object
50 51 52 |
# File 'app/decorators/integral/notification/notification_decorator.rb', line 50 def item @item ||= item_klass.unscoped.find_by_id(subscribable_id) end |
#item_klass ⇒ Object
69 70 71 |
# File 'app/decorators/integral/notification/notification_decorator.rb', line 69 def item_klass subscribable_type.constantize end |
#item_title ⇒ String
Returns formatted title.
55 56 57 |
# File 'app/decorators/integral/notification/notification_decorator.rb', line 55 def item_title decorated_item.present? ? decorated_item.title : '<deleted>' end |
#item_url ⇒ String
Returns Item URL.
15 16 17 |
# File 'app/decorators/integral/notification/notification_decorator.rb', line 15 def item_url decorated_item&.backend_url end |
#model_name ⇒ String
Returns formatted item type.
65 66 67 |
# File 'app/decorators/integral/notification/notification_decorator.rb', line 65 def model_name item_klass.model_name.human end |
#whodunnit ⇒ Integral::User
Returns who carried out the version (if one exists).
24 25 26 27 28 29 30 |
# File 'app/decorators/integral/notification/notification_decorator.rb', line 24 def whodunnit user_id = object.actor_id.to_i return '' if user_id.zero? @user = Integral::User.unscoped.find_by_id(object.actor_id)&.decorate end |
#whodunnit_avatar_url ⇒ String
Returns image linked to whodunnit.
33 34 35 36 37 38 39 |
# File 'app/decorators/integral/notification/notification_decorator.rb', line 33 def whodunnit_avatar_url if whodunnit.present? whodunnit.avatar_url else ActionController::Base.helpers.asset_path('integral/defaults/user_avatar.jpg') end end |
#whodunnit_name ⇒ String
Returns name linked to whodunnit.
42 43 44 45 46 47 48 |
# File 'app/decorators/integral/notification/notification_decorator.rb', line 42 def whodunnit_name if whodunnit.present? whodunnit.name else 'System' end end |