Created
August 10, 2016 05:02
-
-
Save peco8/43619935a314e6465f12cb2f840168c4 to your computer and use it in GitHub Desktop.
AASM basic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Plan < ActiveRecord::Base | |
include AASM | |
aasm column: 'state' do | |
state :pending, initial: true | |
state :processing | |
state :finished | |
state :errored | |
event :process, after: Proc.new { start } do | |
transitions from: :pending, to: :processing | |
end | |
event :finish, after: Proc.new { finish } do | |
transitions from: :processing, to: :finished | |
end | |
event :fail do | |
transitions from: :processing, to: :errored | |
end | |
end | |
validates :stripe_id, uniqueness: true | |
def self.published(stripe_id) | |
plan = find_by(stripe_id: stripe_id) | |
plan.update(published: true) | |
end | |
# 特定のトランザクションが発生した際に以下のものがコールバックされる。 | |
def start | |
puts 'started!!!' | |
end | |
def finish | |
self.finish | |
puts 'finished!!!' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment