2008-02-21 12:32:04 -05:00
|
|
|
class Conversation
|
|
|
|
include AASM
|
|
|
|
|
2011-11-26 15:11:57 -05:00
|
|
|
aasm do
|
|
|
|
state :needs_attention, :initial => true
|
|
|
|
state :read
|
|
|
|
state :closed
|
|
|
|
state :awaiting_response
|
|
|
|
state :junk
|
2008-02-21 12:32:04 -05:00
|
|
|
|
2011-11-26 15:11:57 -05:00
|
|
|
event :new_message do
|
|
|
|
end
|
2008-02-21 12:32:04 -05:00
|
|
|
|
2011-11-26 15:11:57 -05:00
|
|
|
event :view do
|
|
|
|
transitions :to => :read, :from => [:needs_attention]
|
|
|
|
end
|
2008-02-21 12:32:04 -05:00
|
|
|
|
2011-11-26 15:11:57 -05:00
|
|
|
event :reply do
|
|
|
|
end
|
2008-02-21 12:32:04 -05:00
|
|
|
|
2011-11-26 15:11:57 -05:00
|
|
|
event :close do
|
|
|
|
transitions :to => :closed, :from => [:read, :awaiting_response]
|
|
|
|
end
|
2008-02-21 12:32:04 -05:00
|
|
|
|
2011-11-26 15:11:57 -05:00
|
|
|
event :junk do
|
|
|
|
transitions :to => :junk, :from => [:read]
|
|
|
|
end
|
2008-02-21 12:32:04 -05:00
|
|
|
|
2011-11-26 15:11:57 -05:00
|
|
|
event :unjunk do
|
|
|
|
end
|
2008-02-21 12:32:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(persister)
|
|
|
|
@persister = persister
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2015-06-26 03:46:58 -04:00
|
|
|
|
2008-02-21 12:32:04 -05:00
|
|
|
def aasm_read_state
|
|
|
|
@persister.read_state
|
|
|
|
end
|
|
|
|
|
|
|
|
def aasm_write_state(state)
|
|
|
|
@persister.write_state(state)
|
|
|
|
end
|
2015-06-26 03:46:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class ConversationMultiple
|
|
|
|
include AASM
|
|
|
|
|
|
|
|
aasm(:left) do
|
|
|
|
state :needs_attention, :initial => true
|
|
|
|
state :read
|
|
|
|
state :closed
|
|
|
|
state :awaiting_response
|
|
|
|
state :junk
|
|
|
|
|
|
|
|
event :new_message do
|
|
|
|
end
|
|
|
|
|
|
|
|
event :view do
|
|
|
|
transitions :to => :read, :from => [:needs_attention]
|
|
|
|
end
|
|
|
|
|
|
|
|
event :reply do
|
|
|
|
end
|
|
|
|
|
|
|
|
event :close do
|
|
|
|
transitions :to => :closed, :from => [:read, :awaiting_response]
|
|
|
|
end
|
|
|
|
|
|
|
|
event :junk do
|
|
|
|
transitions :to => :junk, :from => [:read]
|
|
|
|
end
|
|
|
|
|
|
|
|
event :unjunk do
|
|
|
|
end
|
|
|
|
end
|
2008-04-29 01:27:56 -04:00
|
|
|
|
2015-06-26 03:46:58 -04:00
|
|
|
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
|
2008-02-21 12:32:04 -05:00
|
|
|
end
|