class Gruf::Interceptors::Context
Runs interceptors in a given request context
Public Class Methods
new(interceptors = nil)
click to toggle source
Initialize the interception context
@param [Array<Gruf::Interceptors::ServerInterceptor>] interceptors
# File lib/gruf/interceptors/context.rb, line 31 def initialize(interceptors = nil) @interceptors = interceptors || [] end
Public Instance Methods
intercept!() { || ... }
click to toggle source
Intercept the given request and run interceptors in a FIFO execution order
# File lib/gruf/interceptors/context.rb, line 38 def intercept!(&block) return yield if @interceptors.none? i = @interceptors.pop return yield unless i logger.debug "Intercepting request with interceptor: #{i.class}" i.call do if @interceptors.any? intercept!(&block) else yield end end end