Skip to content

Instantly share code, notes, and snippets.

@kivanio
Forked from Porta/states.rb
Created June 22, 2014 21:57
Show Gist options
  • Save kivanio/8a541ab9abfa7fc05ed3 to your computer and use it in GitHub Desktop.
Save kivanio/8a541ab9abfa7fc05ed3 to your computer and use it in GitHub Desktop.
module States
extend ActiveSupport::Concern
included do
state_machine :status, :initial => :new do
event :confirm do
transition :new => :confirmed #, :if => lambda {|order| order.email.present?}
end
before_transition :new => :confirmed do |order|
order.send :email_confirmation
#order.send :notify
end
event :invoice do
transition :confirmed => :invoiced
end
before_transition :confirmed => :invoiced do |order|
#order.send :create_invoice
#order.send :email_invoice
#order.send :invoice_alert
#order.send :notify
end
event :pay do
transition :invoiced => :paid
end
before_transition :invoiced => :paid do |order|
#order.send :email_paid
#order.send :notify
end
end
end
module InstanceMethods
def email_confirmation
UserMailer.order_confirmed(self).deliver
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment