Sha256: e2174b8ebaded1017fff970ba87ee3b7518334b9df9990efee15299f0f60bfce
Contents?: true
Size: 980 Bytes
Versions: 43
Compression:
Stored size: 980 Bytes
Contents
module GraphQL class Schema # Given {steps} and {arguments}, call steps in order, passing `(*arguments, next_step)`. # # Steps should call `next_step.call` to continue the chain, or _not_ call it to stop the chain. class MiddlewareChain # @return [Array<#call(*args)>] Steps in this chain, will be called with arguments and `next_middleware` attr_reader :steps # @return [Array] Arguments passed to steps (followed by `next_middleware`) attr_reader :arguments def initialize(steps:, arguments:) # We're gonna destroy this array, so copy it: @steps = steps.dup @arguments = arguments end # Run the next step in the chain, passing in arguments and handle to the next step def call(next_arguments = @arguments) @arguments = next_arguments next_step = steps.shift next_middleware = self next_step.call(*arguments, next_middleware) end end end end
Version data entries
43 entries across 43 versions & 1 rubygems