Madeline - avoiding Command objects by 'Delegate'?

Madeline is a great persistence alternative to databases. However, explicit
Command objects can be a pain to write and error-prone.

Is it possible to avoid writing explicit Command objects by using (and
extending) “delegate”? Could the delegator take care of command-object
wrapping, so the callers still makes normal method calls?

Is it possible to avoid writing explicit Command objects by using (and
extending) “delegate”? Could the delegator take care of command-object
wrapping, so the callers still makes normal method calls?

Have a look at madeleine/automatic.rb. It includes an interceptor
module that can be mixed into the service you’re using Madeleine with
and all the methods are automatically turned into commands. Very nifty.

Instiki uses this method. It goes one step further, though, and pulls
all the Madeleine goodies into one MadeleineService class that you can
inheirit from to have automatic snapshots setup automatically and
convenience methods for accessing the service as a singleton and for
clearing the database.

You can get Instiki (with source of course) from
http://instiki.rubyforge.org.

···


David Heinemeier Hansson,
http://www.basecamphq.com/ – Web-based Project Management
http://www.loudthinking.com/ – Broadcasting Brain

Thanks! Is is nifty.

What is the recommended way to deal with changes to schema / object
structure? I recall seeing this discussed a long time ago on Prevalence but
am interested in the Ruby best practice.

“David Heinemeier Hansson” david@loudthinking.com wrote in message
news:1F2015C4-84CA-11D8-9D10-000A958E6254@loudthinking.com

···

Is it possible to avoid writing explicit Command objects by using (and
extending) “delegate”? Could the delegator take care of command-object
wrapping, so the callers still makes normal method calls?

Have a look at madeleine/automatic.rb. It includes an interceptor
module that can be mixed into the service you’re using Madeleine with
and all the methods are automatically turned into commands. Very nifty.

Instiki uses this method. It goes one step further, though, and pulls
all the Madeleine goodies into one MadeleineService class that you can
inheirit from to have automatic snapshots setup automatically and
convenience methods for accessing the service as a singleton and for
clearing the database.

You can get Instiki (with source of course) from
http://instiki.rubyforge.org.

David Heinemeier Hansson,
http://www.basecamphq.com/ – Web-based Project Management
http://www.loudthinking.com/ – Broadcasting Brain

Its Me wrote:

What is the recommended way to deal with changes to schema / object
structure? I recall seeing this discussed a long time ago on Prevalence but
am interested in the Ruby best practice.

Ruby’s marshalling of instance variables is more flexible than in Java,
so new, changed or removed fields should be less trouble in Ruby.
We can unmarshal instances of a class even if we only have an empty
class declaration for it, which should make upgrade-scripts easier to
write.
Other than that, I think it’s the same issues as when doing object
prevalence in Java.

/Anders

Its Me wrote:

What is the recommended way to deal with changes to schema / object
structure? I recall seeing this discussed a long time ago on Prevalence but
am interested in the Ruby best practice.

Ruby’s marshalling of instance variables is more flexible than in Java,
so new, changed or removed fields should be less trouble in Ruby.
We can unmarshal instances of a class even if we only have an empty
class declaration for it, which should make upgrade-scripts easier to
write.
Other than that, I think it’s the same issues as when doing object
prevalence in Java.

/Anders