• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2017 gRPC authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# GRPC contains the General RPC module.
16module GRPC
17  ##
18  # Represents a registry of added interceptors available for enumeration.
19  # The registry can be used for both server and client interceptors.
20  # This class is internal to gRPC and not meant for public usage.
21  #
22  class InterceptorRegistry
23    ##
24    # An error raised when an interceptor is attempted to be added
25    # that does not extend GRPC::Interceptor
26    #
27    class DescendantError < StandardError; end
28
29    ##
30    # Initialize the registry with an empty interceptor list
31    # This is an EXPERIMENTAL API.
32    #
33    def initialize(interceptors = [])
34      @interceptors = []
35      interceptors.each do |i|
36        base = GRPC::Interceptor
37        unless i.class.ancestors.include?(base)
38          fail DescendantError, "Interceptors must descend from #{base}"
39        end
40        @interceptors << i
41      end
42    end
43
44    ##
45    # Builds an interception context from this registry
46    #
47    # @return [InterceptionContext]
48    #
49    def build_context
50      InterceptionContext.new(@interceptors)
51    end
52  end
53end
54