-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathreadme_example.rb
More file actions
37 lines (32 loc) · 877 Bytes
/
readme_example.rb
File metadata and controls
37 lines (32 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'workflow'
class Article
include Workflow
workflow do
state :new do
event :submit, :transitions_to => :awaiting_review
end
state :awaiting_review do
event :review, :transitions_to => :being_reviewed
end
state :being_reviewed do
event :accept, :transitions_to => :accepted
event :reject, :transitions_to => :rejected
end
state :accepted
state :rejected
end
end
article = Article.new
article.accepted? # => false
article.new? # => true
article.submit!
article.review!
puts article.current_state # => being_reviewed
class Article
def reject
puts "send email to the author here explaining the reason for the rejection"
end
end
article.reject! # will cause a state transition, would persist the new
# state (if inherited from ActiveRecord), and invoke the callback -
# send email to the author.