Class | Delayed::Callback |
In: |
lib/delayed/lifecycle.rb
|
Parent: | Object |
# File lib/delayed/lifecycle.rb, line 55 55: def initialize 56: @before = [] 57: @after = [] 58: 59: # Identity proc. Avoids special cases when there is no existing around chain. 60: @around = lambda { |*args, &block| block.call(*args) } 61: end
# File lib/delayed/lifecycle.rb, line 70 70: def add(type, &callback) 71: case type 72: when :before 73: @before << callback 74: when :after 75: @after << callback 76: when :around 77: chain = @around # use a local variable so that the current chain is closed over in the following lambda 78: @around = lambda { |*a, &block| chain.call(*a) { |*b| callback.call(*b, &block) } } 79: else 80: raise InvalidCallback, "Invalid callback type: #{type}" 81: end 82: end