-
Notifications
You must be signed in to change notification settings - Fork 7
/
state.rb
46 lines (41 loc) · 932 Bytes
/
state.rb
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
38
39
40
41
42
43
44
45
46
module AASM
module SupportingClasses
class State
attr_reader :name, :options
def initialize(name, options={})
@name, @options = name, options
end
def ==(state)
if state.is_a? Symbol
name == state
else
name == state.name
end
end
def call_action(action, record)
action = @options[action]
if action.is_a? Array
action.each do |a|
_call(a, record)
end
else
_call(action, record)
end
end
def for_select
[name.to_s.gsub(/_/, ' ').capitalize, name.to_s]
end
private
def _call(action, record)
case action
when Symbol, String
record.send(action)
when Proc
action.call(record)
when Array
action.each { |a| record.send(a) }
end
end
end
end
end