класс ActiveSupport::Callbacks::CallbackSequence
Выполнять фильтры «до» и «после» в последовательности вместо их объединения с вложенными лямбда-вызовами, см.: github.com/rails/rails/issues/18011
Публичные методы класса
# File activesupport/lib/active_support/callbacks.rb, line 476 def initialize(&call) @call = call @before = [] @after = [] end
Публичные методы экземпляра
# File activesupport/lib/active_support/callbacks.rb, line 487 def after(&after) @after.push(after) self end
# File activesupport/lib/active_support/callbacks.rb, line 492
def around(&around)
CallbackSequence.new do |*args|
around.call(*args) {
self.call(*args)
}
end
end # File activesupport/lib/active_support/callbacks.rb, line 482 def before(&before) @before.unshift(before) self end
# File activesupport/lib/active_support/callbacks.rb, line 500
def call(*args)
@before.each { |b| b.call(*args) }
value = @call.call(*args)
@after.each { |a| a.call(*args) }
value
end
© 2004–2016 David Heinemeier Hansson
Licensed under the MIT License.