Created
October 15, 2010 04:59
-
-
Save Antiarchitect/627637 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Event < ActiveRecord::Base | |
extend ActiveSupport::Memoizable | |
cattr_accessor :year | |
belongs_to :program | |
has_many :financing_periods, :dependent => :destroy | |
def current_period | |
financing_periods.current(@@year).last(:include => [:plain_financings, { :named_financings => :district }]) | |
end | |
def planned_federal_financing | |
current_period ? current_period.planned_federal_financing : 0.0 | |
end | |
memoize :current_period, | |
:planned_federal_financing | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FinancingPeriod < ActiveRecord::Base | |
extend ActiveSupport::Memoizable | |
belongs_to :event | |
has_many :financings, :dependent => :destroy | |
named_scope :current, lambda { |year| {:order => :date, :conditions => ['YEAR(date) = ?', year || Time.now.year.to_int] } } | |
def planned_federal_financing | |
financings.sum(&:planned_federal_financing) | |
end | |
memoize :planned_federal_financing | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program < ActiveRecord::Base | |
extend ActiveSupport::Memoizable | |
acts_as_tree | |
has_many :events | |
... | |
def planned_federal_financing | |
events.sum(&:planned_federal_financing) + children.sum(&:planned_federal_financing) | |
end | |
... | |
memoize :planned_federal_financing | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment