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