lib/rhoconnect/model/js_base.rb in rhoconnect-4.0.0.beta.12 vs lib/rhoconnect/model/js_base.rb in rhoconnect-4.0.0.beta.24
- old
+ new
@@ -7,11 +7,11 @@
attr_accessor :result
def method_missing(method_name,*args)
obj = Object.const_get(self.class.to_s)
if obj.js_method_list.include? method_name.to_s
- package_and_publish(method_name,args)
+ self.class.package_and_publish(self,method_name,current_user,args)
else
log "METHOD #{method_name} NOT DEFINED IN JS MODEL #{self.class.to_s}"
return "#{method_name} method not defined for #{self.class.to_s}"
end
end
@@ -66,49 +66,44 @@
def store_blob(obj,field_name,blob)
blob[:path] = blob[:tempfile].path
rho_methods('storeBlob',blob)
end
- private
+ def self.partition_name(user_id)
+ class_rho_methods('partitionName',{:user_id => user_id})
+ end
+ def self.class_rho_methods(name,args=nil)
+ if has_method? name
+ package_and_publish(self,name,nil,args)
+ else
+ send(name,args)
+ end
+ end
+
+ def self.has_method?(name)
+ self.js_method_list.include? name
+ end
+
def rho_methods(name,args=nil)
- obj = Object.const_get(self.class.to_s)
- if obj.js_method_list.include? name
- package_and_publish(name,args)
+ if self.class.has_method? name
+ self.class.package_and_publish(self,name,self.current_user,args)
else
- sup.send(name,args)
+ send(name,args)
end
end
- def package_and_publish(method_name,args=nil)
+ def self.package_and_publish(caller,method_name,user,args=nil)
json = {
- :klss => self.class.actual_name,
+ :klss => self.actual_name,
:function => method_name,
:args => args,
- :user => current_user.login,
:route => 'request'
}
- NodeChannel.publish_channel_and_wait(json,self)
+ json[:user] = user.login if user
+ NodeChannel.publish_channel_and_wait(json,caller)
end
end
- end
-end
-
-#allows me to call super method by passing string
-class SuperProxy
- def initialize(obj)
- @obj = obj
- end
-
- def method_missing(meth, *args)
- @obj.class.superclass.superclass.instance_method(meth).bind(@obj).call(*args)
- end
-end
-
-class Object
- private
- def sup
- SuperProxy.new(self)
end
end
class String
def classify