| Module | RemoteObject |
| In: |
lib/remote_object.rb
|
Any Ruby object can be remotely accessible if it is accessible from the RemoteObjectController. Only public methods are callable from remote clients.
Clients may invoke the ‘new’ method to create Remote Objects which causes the initial Object ID to be registered in the session and returned to the client as a handle for further calls.
The ClassName and instance number are values saved with the Object ID in the session:
session[ClassName] => instance_number (which is incremented for each 'new')
session[object_id] => {ClassName => instance_number}
For SessionObjects the attributes are saved as follows:
session[[ClassName, instance_number]] => {attr1=>val1, attr2=>val2,....}
Only attributes with session_attr_* accessors are saved. Behavior is reload all before and save atributes through accessor in session, no save all from controller. Not implemented yet
Since objects with SessionObject behavior don’t need any special code in their object (the controller handles the attribute saves) it’s nice to be able to use vanilla objects as SessionObjects depending on context and also to determine whether it is a SessionObject external to the object as well. The following routine allows this. Behavior is reload before and save all attributes after request.
Register the object’s ID, name and instance number in the session If it is a SessionObject, add an entry for instance variables and the number of init args it takes