[Nitro] A few questions
Aleksi.Niemela at cs.helsinki.fi
Mon Jun 20 17:28:57 EDT 2005
David Corbin wrote:
>>>3) Is there something magical about 'db', or does the Database object
>>>effectively act like a singleton? How does the object know it's bound to
>>there is nothing special with db, you can use any variable name you want.
>I don't see where (in the tutorial), the classes are linked to a particular
Classes which will be managed get binding to certain database (ie.
manager which contains a store representing that database) in this
sequence of events:
1) class definition with Og keyword "property" or something alike in it
(like class A; property :name, String; end)
1.1) that triggers Og meta programming which in turn adds methods like
A#name, A#name=, A#find, ...
2) call to Og.setup (at the end of manager.rb)
2.1) which in turn calls in turn Manager#manage_classes which
2.2) manages either given classses or ones it finds through
2.3) which "knows" a class is a managed if it contains attribute __props
(and is not empty)
3) and "managing a class" means
3.1) it will be added a comparator method
3.2) and ogmanager will be set for database given for Og.setup
3.3) it's relations to other classes will be enchanted (ie. has_many
:article, Article will convert to Klass#articles method etc)
Basically the answer to your question is point 2.3, the database object
knows which classes to manage by checking for attribute __props. And a
class knows to which database it should be saved through it's attribute
ogmanager which contains datastore facing database.
More information about the Nitro-general