Permalink
Browse files

Serialize args to remote functions.

  • Loading branch information...
1 parent 07a8b42 commit 491d44c461e807c6a018d7efd2e6f02817b8af55 @steveWang steveWang committed Aug 8, 2011
Showing with 17 additions and 15 deletions.
  1. +2 −2 lib/ruby-now.rb
  2. +15 −13 lib/util.rb
View
@@ -10,8 +10,8 @@ module RubyNow
def self.conn
@@conn
end
- def self.remoteCall name
- Util.remoteCall name
+ def self.remoteCall
+ Util.remoteCall
end
def self.registerFunction name, block
Util.registerFunction name, block
View
@@ -19,26 +19,28 @@ def self.processData hash
puts 'unidentified json, json'
end
end
+ def self.serialize a
+ ((a.is_a?(Hash) && a.has_key?('fqn')) ?
+ (@@functions.has_key?(a['fqn']) ?
+ @@functions[a['fqn']] :
+ (@@closures.has_key?(a['fqn']) ?
+ @@closures[a['fqn']] :
+ self.remoteCall(a['fqn']))):
+ (a.is_a?(Proc) ?
+ (((@@closures[a.to_s] = a) && true) ||
+ {"fqn" => a.to_s}) :
+ a))
+ end
def self.callFunc func, args
- func.call *(args.collect{|a|
- ((a.is_a?(Hash) && a.has_key?('fqn')) ?
- (@@functions.has_key?(a['fqn']) ?
- @@functions[a['fqn']] :
- (@@closures.has_key?(a['fqn']) ?
- @@closures[a['fqn']] :
- self.remoteCall(a['fqn']))):
- (a.is_a?(Proc) ?
- (((@@closures[a.to_s] = a) && true) ||
- {"fqn" => a.to_s}) :
- a))
- })
+ func.call *(args.collect(self.serialize))
end
+
def self.remoteCall a
(lambda{|*args|
self.send_data({ "name" => "rfc",
"args" => [{ "fqn" => a,
- "args" => args }] }.to_json)
+ "args" => args.collect(self.serialize) }] }.to_json)
})
end

0 comments on commit 491d44c

Please sign in to comment.