class CoreExt::Callbacks::CallbackSequence

Execute before and after filters in a sequence instead of chaining them with nested lambda calls, see: github.com/rails/rails/issues/18011

Public Class Methods

new(&call) click to toggle source
# File lib/core_ext/callbacks.rb, line 422
def initialize(&call)
  @call = call
  @before = []
  @after = []
end

Public Instance Methods

after(&after) click to toggle source
# File lib/core_ext/callbacks.rb, line 433
def after(&after)
  @after.push(after)
  self
end
around(&around) click to toggle source
# File lib/core_ext/callbacks.rb, line 438
def around(&around)
  CallbackSequence.new do |arg|
    around.call(arg) {
      self.call(arg)
    }
  end
end
before(&before) click to toggle source
# File lib/core_ext/callbacks.rb, line 428
def before(&before)
  @before.unshift(before)
  self
end
call(arg) click to toggle source
# File lib/core_ext/callbacks.rb, line 446
def call(arg)
  @before.each { |b| b.call(arg) }
  value = @call.call(arg)
  @after.each { |a| a.call(arg) }
  value
end