[Nitro] Og and derived classes...

Andrew Thompson vagabond at cataclysm-software.net
Thu Aug 11 21:01:56 EDT 2005

I'm trying to write some code that stores ruby classes, modules and 
methods. A class can contain both a module and methods, a method can 
also contain methods. In my code classes are a derived class of methods, 
and I've set the has_many to be methods for the module class. The method 
class has belongs_to set to be a module...

However og doesn't seem to like this idea much, is this kinda 
arrangement even possible? It seems that og isn't smart enough to notice 
that class is derived from module.

Here's my stripped down example of what I'm trying to do:


require 'rubygems'
require_gem 'og'

#turn on debugging
$DBG = true

class Doc
     property :name, String

     def initialize(name)
         @name = name

class DocModule < Doc
     has_many :functions, DocMethod #contains many methods

class DocClass < DocModule
     many_to_many :modules, DocModule #may have many modules, and those 
modules may be in other classes

class DocMethod < Doc
     belongs_to :parent, DocModule #belong to a DocModule as DocClass is 
a subclass of DocModule

db = Og.setup(
       :store => 'mysql',
       :name => 'test',
       :user => 'bleh',
       :password => 'something'

testclass = DocClass.new('Testd')
testmethod = DocMethod.new('test')
testmodule = DocModule.new('module')

testmethod.parent = testclass

#save the objects


#this works
testmethod.parent = testclass

#but reports no parents...
puts testmethod.parent

#this causes a crash

#this causes a crash
#puts testclass.functions


I'm also having problems using a filesys store, are there any tips on 
that, developing on a mysql db is a bit annoying as I have to keep 
manually deleting the tables when I mess with the structre. I thought 
Og.create_schema = true would help with that, but apparently it does not..

I really like the idea of og, and really want to use it and nitro, great 
job so far (tho the docs could be better).


More information about the Nitro-general mailing list