Part of DataMapper 2 Is Done – Announcing Virtus 0.5.0

I’m happy to announce that Virtus 0.5.0 was released. It’s sort of a milestone for me as Virtus is now considered feature-complete and I’m quite happy with the code. Further development will only focus on bug fixes and small internal clean ups. We plan to extract smaller pieces into separate gems at some point too. Specifically Coercion mechanism, DescendantsTracker and Equalizer will very likely become separate gems.

So, what’s new in 0.5.0?

Using Virtus in Modules

The release brings support for using Virtus within modules. The feature was requested some time ago but I postponed the implementation until there was a bigger demand. I was a bit worried that supporting this will complicate the code too much but it turned out I was wrong :)

Using Virtus in modules is as easy as this:

Thanks to this feature Representable gem, which now uses Virtus for coercions, can be used in both classes and modules. So enjoy it!

Extending Objects “on the fly”

It is also possible now to dynamically extend objects and define attributes on them. Check this out:

Improved Embedded Value with support for Struct

That’s a small but beautiful addition – you can now use a Struct as an Embedded Value attribute type. Here’s a short example showing what I mean:

You are not forced to use structs of course. You can use a custom class with a custom initialize method and it’s still going to work.

What’s Next?

Virtus is one of the pieces of DataMapper 2, since it’s mostly done we can safely say that a significant part of DM2 is done too. I’m switching my focus to dm-mapper now so expect more work there in the upcoming weeks.

If you haven’t done it yet – I encourage you to try out Virtus and tell me what you think. We want it to be rock solid for DataMapper 2 release!

  • http://twitter.com/mr_robgleeson Rob

    Friendly heads up: l ine 12 and 13 of the third example have a typo (top_lef instead of top_left). Thanks for the article!

    • http://solnic.eu/ solnic

      Thanks. Fixed! :)

  • http://www.padrinorb.com/ DAddYE

    Awesome job! Congrats! But please don’t separate gems, for devs remember every time each name of a gem and their version is complicated… 

    • http://solnic.eu/ solnic

      Don’t be worried. These gems will be “internal” DM2 deps, nobody will even notice.

  • trans

    I am a little concerned about the separate gems too. I always felt DM went a little too far in that respect too, e.g. dm-aggregates.

    So what are the “Coercion”, “DescendentsTracker” and “Equalizers” and why do they makes sense as separate gems –are they at all useful independent of Virtus?

    • http://solnic.eu/ solnic

      In DM2 projects will be organized in a better way. Core gem will provide interfaces that specific adapters will implement. So for example we’ll have aggregation interface with a concrete implementation in various veritas adapters. This means that you will have all the functionality coming from a single place. This is the lesson we’ve learned from DM1 :)

      Regarding extraction from Virtus it’s something that “end users” won’t have to be concerned about. Descendants Tracker and Equalizer are something that multiple DM2 projects will need (right now both Virtus and Veritas have very similar functionality, that’s why we started thinking about extracting it into common, shared gems).

      Coercion would be an exception though. I had few requests that it would be great if coercion functionality could be used stand-alone. It is already separated in Virtus but if you need it you still need to install the gem. That’s why I’m thinking about moving it out to a separate projects.

  • http://blog.steveklabnik.com/ Steve Klabnik

    If it’s feature-complete, why is it 0.5?

    • http://solnic.eu/ solnic

      Cause we still plan some internal refactorings and it’s possible there will be some subtle changes in the public API. I plan to push 1.0.0 when we’re ready with DM2 cause that will be a moment when we can start supporting stable API. Virtus is probably very stable in terms of its features and I don’t expect many bug reports *but* the API may be changed in some places. Like in 0.5.0 I deprecated .attributes in favor of .attribute_set. Minor changes like that can still happen along with some internal refactorings that’s why we will feel more comfortable having it below 1.0.0 for the time being.

      Makes sense?

      • http://blog.steveklabnik.com/ Steve Klabnik

        > internal refactorings

        Shouldn’t matter for a 1.0.

        >  some subtle changes in the public API. 

        Okay, well, that makes sense then. :)

  • Pingback: The Last 2 Weeks in Ruby: Rails 3.2.6, Savon 1.0, RailsInstaller for OS X, Pow 0.4.0, Rails 2 Asset Pipeline