Class: SimpleActivity::Callbacks

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_activity/services/callbacks.rb

Overview

The callback would be the module or class name. It must be responsed to ‘process` method with argument of activity.

Add option if need to process the callback in the backend. The callback constant need to be responsible to add its own backend worker which respond to ‘delay` as per backend_jobs and sidekiq.

Constant Summary collapse

@@callbacks =
[]

Class Method Summary collapse

Class Method Details

.add_callback(name, options = {}) ⇒ Object



22
23
24
25
# File 'lib/simple_activity/services/callbacks.rb', line 22

def self.add_callback(name, options={})
  name = name.to_string unless name.kind_of?(String)
  @@callbacks << {name: name}.merge!(options)
end

.delete_callback(name) ⇒ Object



38
39
40
41
42
# File 'lib/simple_activity/services/callbacks.rb', line 38

def self.delete_callback(name)
  @@callbacks.delete_if do |callback|
    callback[:name] == name
  end
end

.run_callbacks(activity) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/simple_activity/services/callbacks.rb', line 27

def self.run_callbacks(activity)
  @@callbacks.each do |callback|
    const = Object.const_get callback[:name]
    if callback[:backend]
      const.delay.process(activity)
    else
      const.process(activity)
    end
  end
end