Experimental composite metas syntax

0 views
Skip to first unread message

Yurii Rashkovskii

unread,
Mar 8, 2008, 4:50:38 PM3/8/08
to stro...@googlegroups.com
Hey folks,

I was playing with this idea in my mind for a week or so and finally
decided to put it into the code. The basic idea is that since any
document can have multiple metas, why not improving API for this?
Before latest commits, you needed to do things like:

u = User.new :name => "Yurii"
u.metas << Buyer
u.metas << Seller
u.save!

It isn't really nice. So what I have done just a couple of minutes ago
is a special syntax for composite metas. You can simply use Meta#+ to
add meta to meta:

User = Meta.new
# ==> User
Buyer = Meta.new
# ==> Buyer
Seller = Meta.new
# ==> Seller
(User+Buyer+Seller).create! :name => "Yurii"
# ==> #<User,Buyer,Seller __version__: 5bf2..., name: "Yurii",
uuid: "32ae72c8-a1da-4ead-8bfb-d2aa65e727f3">

where created document will have actually three metas:

_[:__meta__]
# ==> [#<StrokeDB::Meta __version__: b6a0..., name: "User", uuid:
"292b3226-8c69-4d21-bb2c-d4d8cd924bf2">, #<StrokeDB::Meta __version__:
d223..., name: "Buyer", uuid: "89d4c62a-b935-42c6-b680-78e1de0b7d9e">,
#<StrokeDB::Meta __version__: 2291..., name: "Seller", uuid:
"52babc48-5bda-4ea1-a4c3-1c931185c290">]

Also (User+Buyer+Seller).find will work just as expected:

# ==> [#<User,Buyer,Seller __version__: 5bf2..., name: "Yurii",
uuid: "32ae72c8-a1da-4ead-8bfb-d2aa65e727f3">]

(please note that order is important, not only in #find but it also
defines a way how combined meta document will look like
[Document#meta]).

Please note that this stuff is not fully complete yet, but as always,
it is already funny to play with it.

Yurii.

Reply all
Reply to author
Forward
0 new messages