2008-01-07 14:11:38 -05:00
|
|
|
module AASM
|
|
|
|
module SupportingClasses
|
|
|
|
class State
|
2008-04-14 19:49:57 -04:00
|
|
|
attr_reader :name, :options
|
2008-01-07 14:11:38 -05:00
|
|
|
|
2008-04-14 19:49:57 -04:00
|
|
|
def initialize(name, options={})
|
|
|
|
@name, @options = name, options
|
2008-01-07 14:11:38 -05:00
|
|
|
end
|
|
|
|
|
2008-05-31 17:33:07 -04:00
|
|
|
def ==(state)
|
|
|
|
if state.is_a? Symbol
|
|
|
|
name == state
|
|
|
|
else
|
|
|
|
name == state.name
|
2008-01-07 14:11:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-05-31 17:33:07 -04:00
|
|
|
def call_action(action, record)
|
|
|
|
action = @options[action]
|
|
|
|
case action
|
|
|
|
when Symbol, String
|
|
|
|
record.send(action)
|
|
|
|
when Proc
|
|
|
|
action.call(record)
|
|
|
|
end
|
2008-01-07 14:11:38 -05:00
|
|
|
end
|
2008-05-31 18:11:18 -04:00
|
|
|
|
|
|
|
def for_select
|
|
|
|
[name.to_s.gsub(/_/, ' ').capitalize, name.to_s]
|
|
|
|
end
|
2008-01-07 14:11:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|