Sha256: 72be3101bea5dd5c59232672a0d7db765042af79ec9c54d7964f0ac6dadf997c

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

class SponsoredDonationKit < Kit
  acts_as_kit :with_approval => true do
    activate :if => :connected?
    activate :if => :has_active_fiscally_sponsored_project

    when_active do |organization|
      organization.can :receive, Donation
    end

    state_machine do
      event :activate_without_prejudice do
        transitions :from => [:fresh, :activated, :pending, :cancelled], :to => :activated
      end

      event :cancel_with_authority do
        transitions :from => [:fresh, :pending, :activated, :cancelled], :to => :cancelled
      end
    end
  end

  def has_active_fiscally_sponsored_project
    organization.has_active_fiscally_sponsored_project?
  end
  
  def friendly_name
    "Sponsored Donations"
  end
  
  def pitch
    "Contact support@artful.ly to learn about Fiscal Sponsorship through Fractured Atlas for your organization"
  end

  def connected?
    errors.add(:requirements, "You need to connect to your Fractured Atlas Membership to active this kit") unless organization.connected?
    organization.connected?
  end

  def exclusive?
    exclusive = !organization.kits.where(:type => alternatives.collect(&:to_s)).any?
    errors.add(:requirements, "You have already activated a mutually exclusive kit.") unless exclusive
    exclusive
  end

  def has_website?
    errors.add(:requirements, "You need to specify a website for your organization.") unless !organization.website.blank?
    !organization.website.blank?
  end

  def self.setup_state_machine
    state_machine do
      state :fresh
      state :pending, :enter => :on_pending
      state :activated, :enter => :on_activation
      state :cancelled

      event :activate do
        transitions :from => [:fresh, :pending], :to => :activated, :guard => :activatable?
      end

      event :activate_without_pending do
        transitions :from => [:fresh, :pending, :cancelled], :to => :activated
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
artfully_ose-1.0.0.rc4 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.0.0.rc3 app/models/kits/sponsored_donation_kit.rb