Sha256: 549a788a50571b1c1b9e2ad2c2c1baff6801b9dd27e0fd5156286ddeb6a961d3
Contents?: true
Size: 1.88 KB
Versions: 6
Compression:
Stored size: 1.88 KB
Contents
class Membership < ActiveRecord::Base include Itemable belongs_to :organization belongs_to :member belongs_to :membership_type has_many :items, :as => :product # Same callbacks that fire before Rails' built-in counter_cache #Except before_destroy is replaced with after_destroy after_create :update_member_counters after_destroy :update_member_counters after_update :update_member_counters scope :current, lambda { |time = Time.now| where("ends_at > ?", time) } scope :lapsed, lambda { |time = Time.now| where("ends_at < ?", time).where("ends_at > ?", time - 1.year) } scope :past, lambda { |time = Time.now| where("ends_at < ?", time - 1.year) } def self.for(membership_type) new.tap do |membership| membership.membership_type = membership_type membership.organization = membership_type.organization membership.price = membership_type.price membership.starts_at = membership_type.starts_at membership.ends_at = membership_type.ends_at end end def update_member_counters self.member.try(:count_memberships) end # TODO: DJ this. Could be thousands of people. def self.for_award(membership_award) membership_award.people.each do |people| membership = Membership.for(membership_award.membership_type) membership.ends_at = membership_award.ends_at membership.sold_price = membership_award.sold_price # create order # Member.for(membership) end end def adjust_expiration_to(new_ends_at) self.ends_at = new_ends_at self.save end def item items.first end def cart_price price end def self.realized_fee 0 end def refundable? false end def exchangeable? false end def returnable? false end def order_summary_description self.membership_type.name end end
Version data entries
6 entries across 6 versions & 1 rubygems