Just a quick announcement that I just pushed a new version of Virtus with support for long awaited features: EmbeddedValue, member type coercions for array/set attributes and ValueObject. Current version is 0.2.0, please give it a try and tell me what you think.
Here’s a quick sneak-preview of what you can do with Virtus:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
class GeoLocation include Virtus::ValueObject attribute :lat, Float attribute :lng, Float end class City include Virtus attribute :name, String attribute :location, GeoLocation attribute :districts, Array[Symbol] end class User include Virtus attribute :name, String attribute :age, Integer attribute :city, City end user = User.new( :name => ‘John’, :age => 29, :city => { :name => ‘NYC’, :location => { :lat => ‘1234567.89’, :lng => ‘9876543.21’ }, :districts => [ ‘one’, ‘two’, ‘three’ ] } ) user.city.location.lat # => 1234567.89 user.city.districts # => [ :one, :two, :three ] |
I hope you’re going to enjoy it and find it useful in your projects. In case of any issues please report them on Github.
Huge props go to Dan Kubb, Emmanuel Gomez and Yves Senn for helping me with recent releases! Thanks guys!
