If :mapping option for an aggregated attribute has mappings to a
delegated attribute/method, :constructor receives "nil" instead of
the expected value.
Example:
class OrderTransaction < ActiveRecord::Base
belongs_to :order
delegate :currency, :to => :order
composed_of :amount
:class_name => "Money",
:mapping => [%w(amount cents), %w(currency currency_as_string)],
:constructor => proc { |cents, currency| Money.new(cents, currency) }
end
Later, such order_transaction.amount.currency is always "USD"
(default currency for Money). Debugging reveals that "currency"
passed to the :constructor proc is "nil".
This is caused by doing explicit "read_attribute" in
aggregations.rb (which doesn't take into account delegations and
such). I suggest replacing "read_attribute(attr_name)" with
"self.send(attr_name)".
The patch is attached.