Class: Eventish::ActiveJobEvent

Inherits:
ActiveJob::Base
  • Object
show all
Extended by:
EventApi
Defined in:
lib/eventish/active_job_event.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EventApi

<=>, after_event, before_event, event_name, priority, subscribe, subscribe_all, unsubscribe

Class Method Details

.trigger(target, args, &_block) ⇒ Object



23
24
25
26
27
# File 'lib/eventish/active_job_event.rb', line 23

def trigger(target, args, &_block)
  return unless new.callable?(target)

  perform_later(target, args)
end

Instance Method Details

#call(_target, _args, &_block) ⇒ Object

Raises:

  • (NotImplementedError)


5
6
7
# File 'lib/eventish/active_job_event.rb', line 5

def call(_target, _args, &_block)
  raise NotImplementedError
end

#callable?(_target) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/eventish/active_job_event.rb', line 9

def callable?(_target)
  true
end

#perform(target, args) ⇒ Object



13
14
15
16
17
18
# File 'lib/eventish/active_job_event.rb', line 13

def perform(target, args)
  self.class.before_event.each { |plugin| plugin.call(target, args, event: self, hook: :before) }
  call(target, args)
  self.class.after_event.each { |plugin| plugin.call(target, args, event: self, hook: :after) }
  self
end