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.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Initialize method to create view context in this OptionalTarget instance

Parameters:

  • options (Hash) (defaults to: {})

    Options for initializing target

Options Hash (options):

  • :skip_initializing_target (Boolean) — default: false

    Whether skip calling initialize_target method

  • others (Hash)

    Options for initializing target



10
11
12
# File 'lib/activity_notification/optional_targets/base.rb', line 10

def initialize(options = {})
  initialize_target(options) unless options.delete(:skip_initializing_target)
end

Instance Method Details

#initialize_target(_options = {}) ⇒ Object

Initialize method to be overridden in user implementation class

Parameters:

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

    Options for initializing

Raises:

  • (NotImplementedError)


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

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

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

Publishing notification method to be overridden in user implementation class

Parameters:

  • _notification (Notification)

    Notification instance

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

    Options for publishing

Raises:

  • (NotImplementedError)


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

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

#to_optional_target_nameObject

Returns demodulized symbol class name as optional target name

Returns:

  • Demodulized symbol class name as optional target name



16
17
18
# File 'lib/activity_notification/optional_targets/base.rb', line 16

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