Class: Thrift::Middleware::MultiMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/thrift/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(middlewares) ⇒ MultiMiddleware

Returns a new instance of MultiMiddleware.



26
27
28
# File 'lib/thrift/middleware.rb', line 26

def initialize(middlewares)
  @middlewares = middlewares
end

Instance Method Details

#handle_bidi_stream(_mth, args, istream, ostream, &block) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/thrift/middleware.rb', line 46

def handle_bidi_stream(_mth, args, istream, ostream, &block)
  @middlewares.reverse.reduce(block) do |acc, m|
    Proc.new do |args, istream, ostream|
      m.handle_bidi_stream(mth, args, istream, ostream) do |args, istream, ostream|
        acc.call(args, istream, ostream)
      end
    end
  end.call(args, istream, ostream)
end

#handle_binary(mth, args = {}, &block) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/thrift/middleware.rb', line 38

def handle_binary(mth, args = {}, &block)
  @middlewares.reverse.reduce(block) do |acc, m|
    Proc.new do |args|
      m.handle_binary(mth, args) { |args| acc.call(args) }
    end
  end.call(args)
end

#handle_inbound_stream(_mth, args, istream, &block) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/thrift/middleware.rb', line 56

def handle_inbound_stream(_mth, args, istream, &block)
  @middlewares.reverse.reduce(block) do |acc, m|
    Proc.new do |args, istream|
      m.handle_bidi_stream(mth, args, istream) do |args, istream|
        acc.call(args, istream)
      end
    end
  end.call(args, istream)
end

#handle_outbound_stream(_mth, args, ostream, &block) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/thrift/middleware.rb', line 66

def handle_outbound_stream(_mth, args, ostream, &block)
  @middlewares.reverse.reduce(block) do |acc, m|
    Proc.new do |args, ostream|
      m.handle_bidi_stream(mth, args, ostream) do |args, ostream|
        acc.call(args, ostream)
      end
    end
  end.call(args, ostream)
end

#handle_unary(mth, args = {}, &block) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/thrift/middleware.rb', line 30

def handle_unary(mth, args = {}, &block)
  @middlewares.reverse.reduce(block) do |acc, m|
    Proc.new do |args|
      m.handle_unary(mth, args) { |args| acc.call(args) }
    end
  end.call(args)
end