Expose Association

Usage:

Suppose you have this two classes:


class Address < ActiveRecord::Base 
  belongs_to :contact
end

class Contact < ActiveRecord::Base

  has_one :primary_address, :class_name => 'Address'
  expose_association :primary_address, prefix: true, class: Address do
    expose :address_line_1, :address_line_2, :city
    expose :phone_number, prefix: false
    expose :country, prefix: 'primary'
  end

end

You'll be able to use this class like this:


contact = Contact.new
contact.primary_address_address_line_1 = "122 Fake St."
contact.primary_address_address_line_2 = "Apt. 45"
contact.primary_address_city = "Beverly Hill"
contact.phone_number = "123-123-1234"
contact.primary_country = "Argentina"
contact.save

Specs?


contact.primary_address.should be_a_kind_of(Address)
...

# Check te real ones on the spec folder

MIT License.