title: ActiveRecord "has_aggregate" meta-programming capability?
body: <p>Is there anything out there that provides a "has_aggregate" meta-programming capability?</p>
  
  <p>For example, assume you have a model that provides the following methods:</p>
  
  <pre><code>class Customer &lt; ActiveRecord::Base
  
    has_many :orders
  
    def total_orders
      orders.count
    end
  
    def total_spent
      orders.sum(:total_amount)
    end
  
  end
  </code></pre>
  
  <p>Is there any feature in ActiveRecord (or a gem) that would allow syntax similar to this?</p>
  
  <pre><code>class Customer &lt; ActiveRecord::Base
  
    has_many :orders
  
    has_aggregate :total_orders, :orders, :count
  
    has_aggregate :total_spent, :orders, :sum, :total_amount
  
  end
  </code></pre>