Class: ActivityNotification::OptionalTarget::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/activity_notification/optional_targets/base.rb

Overview

Abstract optional target class to develop optional notification target class.

Direct Known Subclasses

AmazonSNS, Slack

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Base

Initialize method to create view context in this OptionalTarget instance



11
12
13
14
15
16
17
18
19
# File 'lib/activity_notification/optional_targets/base.rb', line 11

def initialize
  @view_context = ActionView::Base.new(ActionController::Base.view_paths, {})
  @view_context.class_eval do 
    include Rails.application.routes.url_helpers
    def default_url_options
      ActionMailer::Base.default_url_options
    end
  end
end

Instance Attribute Details

#view_context ⇒ Object

View context to render notification message

Returns:

  • View context to render notification message



8
9
10
# File 'lib/activity_notification/optional_targets/base.rb', line 8

def view_context
  @view_context
end

Instance Method Details

#initialize_target(_options = {}) ⇒ Object

Initialize method to be overriden in user implementation class

Parameters:

  • _options (Hash) (defaults to: {}) —

    Options for initializing

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/activity_notification/optional_targets/base.rb', line 29

def initialize_target(_options = {})
  raise NotImplementedError, "You have to implement #{self.class}##{__method__}"
end

#notify(_notification, _options = {}) ⇒ Object

Publishing notification method to be overriden in user implementation class

Parameters:

  • _notification (Notification) —

    Notification instance

  • _options (Hash) (defaults to: {}) —

    Options for publishing

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/activity_notification/optional_targets/base.rb', line 36

def notify(_notification, _options = {})
  raise NotImplementedError, "You have to implement #{self.class}##{__method__}"
end

#to_optional_target_name ⇒ Object

Returns demodulized symbol class name as optional target name

Returns:

  • Demodulized symbol class name as optional target name



23
24
25
# File 'lib/activity_notification/optional_targets/base.rb', line 23

def to_optional_target_name
  self.class.name.demodulize.underscore.to_sym
end