Class: Decidim::Events::BaseEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/decidim/events/base_event.rb

Overview

This class serves as a base for all event classes. Event classes are intended to add more logic to a ‘Decidim::Notification` and are used to render them in the notifications dashboard and to generate other notifications (emails, for example).

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:, event_name:, user:, extra:) ⇒ BaseEvent

Initializes the class.

event_name - a String with the name of the event. resource - the resource that received the event user - the User that receives the event extra - a Hash with extra information of the event.



38
39
40
41
42
43
# File 'lib/decidim/events/base_event.rb', line 38

def initialize(resource:, event_name:, user:, extra:)
  @event_name = event_name
  @resource = resource
  @user = user
  @extra = extra.with_indifferent_access
end

Class Method Details

.typesObject

Public: Stores all the notification types this event can create. Please, do not overwrite this method, consider it final. Instead, add values to the array via modules, take the ‘NotificationEvent` module as an example:

Example:

module WebPushNotificationEvent
  extend ActiveSupport::Concern

  included do
    types << :web_push_notifications
  end
end

class MyEvent < Decidim::Events::BaseEvent
  include WebPushNotificationEvent
end

MyEvent.types # => [:web_push_notifications]


28
29
30
# File 'lib/decidim/events/base_event.rb', line 28

def self.types
  @types ||= []
end

Instance Method Details

#resource_locatorObject

Caches the locator for the given resource, so that we can find the resource URL.



47
48
49
# File 'lib/decidim/events/base_event.rb', line 47

def resource_locator
  @resource_locator ||= Decidim::ResourceLocatorPresenter.new(resource)
end

#resource_pathObject

Caches the path for the given resource.



52
53
54
# File 'lib/decidim/events/base_event.rb', line 52

def resource_path
  @resource_path ||= resource_locator.path
end

#resource_urlObject

Caches the URL for the given resource.



57
58
59
# File 'lib/decidim/events/base_event.rb', line 57

def resource_url
  @resource_url ||= resource_locator.url
end