2008-02-21 12:32:04 -05:00
|
|
|
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'aasm')
|
|
|
|
|
|
|
|
class Conversation
|
|
|
|
include AASM
|
|
|
|
|
2008-02-21 12:59:28 -05:00
|
|
|
aasm_initial_state :needs_attention
|
2008-02-21 12:32:04 -05:00
|
|
|
|
2008-02-21 12:59:28 -05:00
|
|
|
aasm_state :needs_attention
|
|
|
|
aasm_state :read
|
|
|
|
aasm_state :closed
|
|
|
|
aasm_state :awaiting_response
|
|
|
|
aasm_state :junk
|
2008-02-21 12:32:04 -05:00
|
|
|
|
2008-02-21 12:59:28 -05:00
|
|
|
aasm_event :new_message do
|
2008-02-21 12:32:04 -05:00
|
|
|
end
|
|
|
|
|
2008-02-21 12:59:28 -05:00
|
|
|
aasm_event :view do
|
2008-02-21 12:32:04 -05:00
|
|
|
transitions :to => :read, :from => [:needs_attention]
|
|
|
|
end
|
|
|
|
|
2008-02-21 12:59:28 -05:00
|
|
|
aasm_event :reply do
|
2008-02-21 12:32:04 -05:00
|
|
|
end
|
|
|
|
|
2008-02-21 12:59:28 -05:00
|
|
|
aasm_event :close do
|
2008-02-21 12:32:04 -05:00
|
|
|
transitions :to => :closed, :from => [:read, :awaiting_response]
|
|
|
|
end
|
|
|
|
|
2008-02-21 12:59:28 -05:00
|
|
|
aasm_event :junk do
|
2008-02-21 12:32:04 -05:00
|
|
|
transitions :to => :junk, :from => [:read]
|
|
|
|
end
|
|
|
|
|
2008-02-21 12:59:28 -05:00
|
|
|
aasm_event :unjunk do
|
2008-02-21 12:32:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(persister)
|
|
|
|
@persister = persister
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
def aasm_read_state
|
|
|
|
@persister.read_state
|
|
|
|
end
|
|
|
|
|
|
|
|
def aasm_write_state(state)
|
|
|
|
@persister.write_state(state)
|
|
|
|
end
|
|
|
|
end
|