Sha256: 1c52e24eec7a5c3b81dad6d38c6bfcd669f0a7e7e99cd46eb631895909f4f6e7

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

class MembershipKit < Kit
  include ActionView::Helpers::SanitizeHelper

  acts_as_kit :with_approval => true, :admin_only => true do
    approve  :unless => :no_bank_account?

    self.configurable = true

    state_machine do
      state :cancelled, :enter => :kit_cancelled
    end

    when_active do |organization|
      organization.can :access, :membership
    end
  end

  before_save :initialize_accessors
  before_save :sanitize_accessors

  ACCESSORS = [ :marketing_copy_heading, :marketing_copy_sidebar ]
  
  ACCESSORS.each do |accessor|
    attr_accessible accessor
  end
  
  store :settings, :accessors => ACCESSORS

  def friendly_name
    "Membership"
  end  

  def no_bank_account?
    errors.add(:requirements, "Your organization needs bank account information first.") if organization.bank_account.nil?
    organization.bank_account.nil?
  end

  def pitch
    "Sell Memberships!"
  end

  def configured?
    membership_state == "configured"
  end

  def configured!
    settings[:membership_state] = "configured"
    save
  end

  def initialize_accessors
    ACCESSORS.each do |accessor|
      self.send("#{accessor}=", "") if self.send("#{accessor}").nil?
    end  
  end

  def sanitize_accessors
    ACCESSORS.each do |accessor|
      self.send("#{accessor}=", (sanitize self.send(accessor)))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
artfully_ose-1.2.0.pre.23 app/models/kits/membership_kit.rb
artfully_ose-1.2.0.pre.21 app/models/kits/membership_kit.rb
artfully_ose-1.2.0.pre.20 app/models/kits/membership_kit.rb