Class: Celluloid::Call
- Inherits:
-
Object
- Object
- Celluloid::Call
- Defined in:
- lib/celluloid/calls.rb,
lib/celluloid/call/sync.rb,
lib/celluloid/call/async.rb,
lib/celluloid/call/block.rb
Overview
Calls represent requests to an actor
Defined Under Namespace
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Instance Method Summary collapse
- #check(obj) ⇒ Object
- #dispatch(obj) ⇒ Object
- #execute_block_on_receiver ⇒ Object
-
#initialize(method, arguments = [], block = nil) ⇒ Call
constructor
A new instance of Call.
Constructor Details
#initialize(method, arguments = [], block = nil) ⇒ Call
Returns a new instance of Call.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/celluloid/calls.rb', line 6 def initialize(method, arguments = [], block = nil) @retry = 0 @method = method @arguments = arguments if block if Celluloid.exclusive? # FIXME: nicer exception raise "Cannot execute blocks on sender in exclusive mode" end @block = Proxy::Block.new(Celluloid.mailbox, self, block) else @block = nil end end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
4 5 6 |
# File 'lib/celluloid/calls.rb', line 4 def arguments @arguments end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
4 5 6 |
# File 'lib/celluloid/calls.rb', line 4 def block @block end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
4 5 6 |
# File 'lib/celluloid/calls.rb', line 4 def method @method end |
Instance Method Details
#check(obj) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/celluloid/calls.rb', line 30 def check(obj) # NOTE: don't use respond_to? here begin meth = obj.method(@method) rescue NameError raise NoMethodError, "undefined method `#{@method}' for #<#{obj.class}:0x#{obj.object_id.to_s(16)}>" end arity = meth.arity if arity >= 0 if @arguments.size != arity e = ArgumentError.new("wrong number of arguments (#{@arguments.size} for #{arity})") e.set_backtrace(caller << "#{meth.source_location.join(':')}: in `#{meth.name}`") raise e end elsif arity < -1 mandatory_args = -arity - 1 if arguments.size < mandatory_args e = ArgumentError.new("wrong number of arguments (#{@arguments.size} for #{mandatory_args}+)") e.set_backtrace(caller << "#{meth.source_location.join(':')}: in `#{meth.name}`") raise e end end rescue => ex raise AbortError, ex end |
#dispatch(obj) ⇒ Object
25 26 27 28 |
# File 'lib/celluloid/calls.rb', line 25 def dispatch(obj) check(obj) obj.public_send(@method, *@arguments, &(@block && @block.to_proc)) end |
#execute_block_on_receiver ⇒ Object
21 22 23 |
# File 'lib/celluloid/calls.rb', line 21 def execute_block_on_receiver @block && @block.execution = :receiver end |