Sha256: e19e34f291e2bf047b620e90194c9131306c24d5cb6fb300eccf849ff3b8e98b

Contents?: true

Size: 1.87 KB

Versions: 31

Compression:

Stored size: 1.87 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@fracturedatlas.org to learn about Fiscal Sponsorship through Fractured Atlas."
  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

31 entries across 31 versions & 1 rubygems

Version Path
artfully_ose-1.2.0 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.beta.1 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.alpha.2 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.alpha.1 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.pre.27 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.pre.26 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.pre.24 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.pre.23 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.pre.21 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.pre.20 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.pre.19 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.pre.18 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.pre.17 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.pre.16 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.pre.15 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.pre.12 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.pre.11 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.pre.10 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.pre.9 app/models/kits/sponsored_donation_kit.rb
artfully_ose-1.2.0.pre.8 app/models/kits/sponsored_donation_kit.rb