{"issue":{"created_at":"2011-11-17T22:00:16Z","state":"open","updated_at":"2011-11-18T09:40:13Z","user":{"gravatar_id":"3d698e2872c07061a455d9e250861235","id":5402,"url":"https://api.github.com/users/senny","login":"senny","avatar_url":"https://secure.gravatar.com/avatar/3d698e2872c07061a455d9e250861235?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"comments":2,"body":"It would be nice if virtus had like a submodule for building ValueObjects. On top of my head this could look something like:\r\n\r\n```ruby\r\nclass GeoLocation\r\n  include Virtus::ValueObject\r\n\r\n  attribute :latitude, Float\r\n  attribute :longitude, Float\r\nend\r\n```\r\n\r\nThe `Virtus::ValueObject` module would set some sane defaults for building ValueObjects like:\r\n\r\n* They should be immutable so the setters are private\r\n* They should be == when all the properties are equal\r\n* We need to overwrite the #hash method since we defined a new == method\r\n* the constructor should verify that all the properties have been set since the setters are not available. (not completely sure about that one. There might be cases where optional attributes are welcome)\r\n\r\n```ruby\r\nplace = GeoLocation.new(:latitute => 40.73216945026674, :longitude => -74.091796875)\r\nthe_same_place = GeoLocation.new(:latitute => 40.73216945026674, :longitude => -74.091796875)\r\nplace == the_same_place # => true\r\n\r\nhash = {palce => 1}\r\nhash[the_same_palce] # => 1\r\n\r\nplace.latitude = -74.091796875 # => ERROR: Attempt to call private method\r\n```","assignee":null,"id":2274277,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"number":40,"labels":[],"title":"special treatment for ValueObjects","closed_at":null,"html_url":"https://github.com/solnic/virtus/issues/40","milestone":null,"url":"https://api.github.com/repos/solnic/virtus/issues/40"},"action":"created","comment":{"created_at":"2011-11-18T09:40:13Z","updated_at":"2011-11-18T09:40:13Z","user":{"gravatar_id":"3d698e2872c07061a455d9e250861235","id":5402,"url":"https://api.github.com/users/senny","login":"senny","avatar_url":"https://secure.gravatar.com/avatar/3d698e2872c07061a455d9e250861235?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"body":"@blambeau I'm not sure if veritas should automatically generate these `with_XXX` methods, which return new ValueObjects based on self. I think this is more of a domain concern to provide the operations necessary to work with the value objects at hand. Sometimes this might be necessary but I guess we should not try to guess what the application needs.\r\n\r\nThanks for the LatLng hint ;) I fixed it in the Ticket description.","id":2787372,"url":"https://api.github.com/repos/solnic/virtus/issues/comments/2787372"}}