Class: IbRubyProxy::Client::CallbacksResponseHandler::BlockCallbackHandler

Inherits:
Object
  • Object
show all
Includes:
Util::HasLogger
Defined in:
lib/ib_ruby_proxy/client/callbacks_response_handler.rb

Overview

b_proxy_service.rb:13@private

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::HasLogger

#logger

Constructor Details

#initialize(discriminate_by_argument_nth) ⇒ BlockCallbackHandler

Returns a new instance of BlockCallbackHandler.



99
100
101
102
# File 'lib/ib_ruby_proxy/client/callbacks_response_handler.rb', line 99

def initialize(discriminate_by_argument_nth)
  @discriminate_by_argument_nth = discriminate_by_argument_nth
  @blocks_by_discriminator = {}
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



97
98
99
# File 'lib/ib_ruby_proxy/client/callbacks_response_handler.rb', line 97

def block
  @block
end

#discriminate_by_argument_nthObject (readonly)

Returns the value of attribute discriminate_by_argument_nth.



97
98
99
# File 'lib/ib_ruby_proxy/client/callbacks_response_handler.rb', line 97

def discriminate_by_argument_nth
  @discriminate_by_argument_nth
end

Instance Method Details

#callback_received(callback_name, *arguments) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/ib_ruby_proxy/client/callbacks_response_handler.rb', line 119

def callback_received(callback_name, *arguments)
  if callback_name.to_s == 'error'
    raise StandardError, arguments.join('. ')
  else
    block = if @discriminate_by_argument_nth
              @blocks_by_discriminator[arguments[@discriminate_by_argument_nth]]
            else
              @block
            end

    block&.call(callback_name, *arguments)
  end
end

#method_invoked(*arguments, &block) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ib_ruby_proxy/client/callbacks_response_handler.rb', line 104

def method_invoked(*arguments, &block)
  if @discriminate_by_argument_nth
    discrminator = arguments[@discriminate_by_argument_nth]
    unless discrminator
      raise "No argument #{@discriminate_by_argument_nth} to discriminate with?"\
            " #{arguments.inspect}"
    end

    @blocks_by_discriminator[discrminator] = block
  else
    @block = block
  end
  nil
end