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,....}

Methods

Public Instance methods

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

retrieve a Class name from an object ID

get the number of init args this object takes

get the Class object from the Class name string

destroy the session storage for this instance session don’t have normal hash behavior so you cannot do session.delete(key), instead you do session[key] = nil

reload all instance variables from the session

save all instance variables in the session

[Validate]