Module: Pione::TupleSpace::TupleSpaceServerMethod

Included in:
TupleSpaceServer
Defined in:
lib/pione/tuple-space/tuple-space-server.rb

Class Method Summary collapse

Class Method Details

.tuple_space_interface(name, opt = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 4

def self.tuple_space_interface(name, opt={})
  define_method(name) do |*args, &b|
    # convert tuple space form
    _args = args.map do |obj|
      tuple_form = obj.respond_to?(:to_tuple_space_form)
      tuple_form ? obj.to_tuple_space_form : obj
    end
    # check arguments
    if opt.has_key?(:validator)
      opt[:validator].call(args)
    end
    # send a message to the tuple space
    result = @ts.__send__(name, *_args, &b)
    # convert the result to tuple object
    if converter = opt[:result]
      converter.call(result)
    else
      result
    end
  end
end