Sha256: a54f0a1f51e0829e126b87fbe89a7323aaf1ffaac4ebe4d94341ae4f24cff64f

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

class MembershipType < ActiveRecord::Base
  attr_accessible :name, :price, :fee, :number_of_shows, 
                  :plan, :on_sale, :description, :ends_at, 
                  :starts_at, :duration, :type, :period, :number_of_tickets, :sales_start_at, :sales_end_at

  belongs_to :organization
  has_many :memberships
  has_many :members, :through => :memberships
  belongs_to :segment

  after_create :create_list_segment
  
  default_scope order("created_at DESC")

  scope :storefront, where(:on_sale => true).where("sales_start_at < ? or sales_start_at is null", DateTime.now).where("sales_end_at > ? or sales_end_at is null", DateTime.now)
  scope :on_sale, where(:on_sale => true)

  def membershipize
    self.name.end_with?("Membership") ? self.name : self.name + " Membership"
  end

  def create_list_segment
    @search = organization.searches.create({:membership_type => self})
    @segment = organization.segments.create({:search => @search, :name => self.name})
    self.segment = @segment
    save
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
artfully_ose-1.2.0.pre.12 app/models/membership_type.rb
artfully_ose-1.2.0.pre.11 app/models/membership_type.rb
artfully_ose-1.2.0.pre.10 app/models/membership_type.rb