nandosola / dilithium-rb

A tiny framework to power your enterprise-ish stuff in Ruby
BSD 3-Clause "New" or "Revised" License
3 stars 3 forks source link

ImmutableEntityReference should delegate to @resolved_entity #35

Open mcamou opened 10 years ago

mcamou commented 10 years ago

If you want to access the attributes of the entity pointed to by ImmutableEntityReference, you have to always call it through resolved_entity:

class Address < BaseEntity
  attribute :street, String
  attribute :city, String
  attribute :zip, String
end
class User < BaseEntity
  attribute :name, String
  reference :address, Address
end

So if you want to access a user's address data, you need to do:

user.address.resolved_entity.city
user.address.resolved_entity.zip
# Or store user.address.resolved_entity in a variable

What I propose is that the ImmutableEntityReference include delegate methods that correspond to the resolved_entity's attributes.

Advantage: Ease of use Disadvantage: A bit of magic, it's not explicit exactly what is happening.