Class Root
In: lib/core/root.rb
Parent: Object
Root
dot/f_14.png

The Root class is the mother of all objects.

Methods

add_event   clone   delete_object   get_object   inspect   new   parse   put_object   world  

Public Class methods

Create a new Root

name
Every object needs a name
owner
The owner id of this object
return
A handle to the new Object

[Source]

# File lib/core/root.rb, line 30
  def initialize(name, owner)
    self.id                     # The database id of the object
    self.name = name            # The displayed name of the object
    self.owner = owner || id    # The owner of the object or itself.
    self.desc = ""              # The description of the object
    self.created_on = Time.now
    self.updated_on = created_on.dup
  end

Public Instance methods

[Source]

# File lib/core/root.rb, line 76
  def add_event(from,to,kind,msg=nil)
    Engine.instance.eventmgr.add_event(from,to,kind,msg)
  end

Clone an object This does a deepcopy then assign a new database id

return
A handle to the new Object

[Source]

# File lib/core/root.rb, line 54
  def clone
    newobj = Marshal.load(Marshal.dump(self))
    props = newobj.instance_variable_get(:@props)
    props[:id] = Engine.instance.db.getid
    put_object(newobj)
    newobj
  rescue
    log.error "Clone failed"
    nil
  end

[Source]

# File lib/core/root.rb, line 88
  def delete_object(oid)
    Engine.instance.db.delete(oid)
  end

[Source]

# File lib/core/root.rb, line 80
  def get_object(oid)
    Engine.instance.db.get(oid)
  end

formatted dump of object properties

return
a string

[Source]

# File lib/core/root.rb, line 41
  def inspect
    s = ''
    @props.each do |key,val|
      s << sprintf("%-20.20s : %-40.40s\n", key.to_s, val.inspect)
    end
    s
  end

All command input routed through here and parsed.

m
The input message to be parsed
return
false or true depending on whether command succeeded.

[Source]

# File lib/core/root.rb, line 68
  def parse(m)
    false
  end

[Source]

# File lib/core/root.rb, line 84
  def put_object(obj)
    Engine.instance.db.put(obj)
  end

[Source]

# File lib/core/root.rb, line 72
  def world
    Engine.instance.db.get(0)
  end

[Validate]