Class: Dizby::InvokeMethod
- Inherits:
-
Object
- Object
- Dizby::InvokeMethod
- Defined in:
- lib/dizby/worker/invoke_method.rb
Instance Method Summary collapse
- #call_block(block, *args) private
- #handle_jump_error(err) private
-
#initialize(server, obj, msg, argv, block) ⇒ InvokeMethod
constructor
A new instance of InvokeMethod.
- #perform
- #send_to_object private
Constructor Details
#initialize(server, obj, msg, argv, block) ⇒ InvokeMethod
Returns a new instance of InvokeMethod.
12 13 14 15 16 17 18 19 |
# File 'lib/dizby/worker/invoke_method.rb', line 12 def initialize(server, obj, msg, argv, block) @obj = obj @msg_id = msg.to_sym @argv = argv @block = block && proc { |*args| call_block(block, *args) } @server = server end |
Instance Method Details
#call_block(block, *args) (private)
38 39 40 41 42 43 44 45 46 |
# File 'lib/dizby/worker/invoke_method.rb', line 38 def call_block(block, *args) if args.size == 1 && args[0].is_a?(Array) args[0] = DistributedArray.new(args[0], @server) end block.call(*args) rescue LocalJumpError handle_jump_error($!) end |
#handle_jump_error(err) (private)
48 49 50 51 52 53 54 55 |
# File 'lib/dizby/worker/invoke_method.rb', line 48 def handle_jump_error(err) case err.reason when :break err.exit_value else fail err end end |
#perform
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dizby/worker/invoke_method.rb', line 21 def perform result = send_to_object # TODO: do we care what the @msg_id is? # Should we convert to a DistributedArray regardless? if @msg_id == :to_ary && result.class == Array result = DistributedArray.new(result, @server) end [true, result] rescue StandardError, ScriptError, Interrupt @server.log.backtrace($!) [false, $!] end |
#send_to_object (private)
57 58 59 |
# File 'lib/dizby/worker/invoke_method.rb', line 57 def send_to_object @obj.__send__(@msg_id, *@argv, &@block) end |