ActiveRecord supports composed_of for value objects which is
fantastic but one thing that it doesn't seem to support (or at least
I am unable to find any documentation for) validation of the value
For example, given the following:
class Message < ActiveRecord::Base
composed_of :sender, :class_name => 'EmailAddress'
composed_of :recipient, :class_name => 'EmailAddress'
attr_reader :name, :address
def initialize(name, address)
@name, @address = name, address
How can I best take advantage of Rails' validation, given that I'd
like to only specify the validation rules for EmailAddress once. The
validation rules might look something like: