Class: Delayed::Master::Callbacks
- Inherits:
-
Object
- Object
- Delayed::Master::Callbacks
- Defined in:
- lib/delayed/master/callbacks.rb
Instance Method Summary collapse
- #call(event, *args, &block) ⇒ Object
-
#initialize(config) ⇒ Callbacks
constructor
A new instance of Callbacks.
- #run(name, *args, &block) ⇒ Object
Constructor Details
#initialize(config) ⇒ Callbacks
Returns a new instance of Callbacks.
6 7 8 |
# File 'lib/delayed/master/callbacks.rb', line 6 def initialize(config) @config = config end |
Instance Method Details
#call(event, *args, &block) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/delayed/master/callbacks.rb', line 10 def call(event, *args, &block) run(:"before_#{event}", *args) result = run(:"around_#{event}", *args, &block) run(:"after_#{event}", *args) result end |
#run(name, *args, &block) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/delayed/master/callbacks.rb', line 17 def run(name, *args, &block) callbacks = get_callbacks(name) if block callbacks.reverse.reduce(block) { |ret, c| -> { c.call(*args, &ret) } }.call else callbacks.each { |c| c.call(*args) } end end |