ramon (owner)

Revisions

gist: 124501 Download_button fork
public
Public Clone URL: git://gist.github.com/124501.git
Embed All Files: show embed
Text #
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
47
48
49
50
51
52
53
54
55
class Message < ActiveRecord::Base
  belongs_to :from, :class_name => "User"
  belongs_to :to, :class_name => "User"
 
  acts_as_tree :order => "updated_at DESC"
 
  state_machine :sent_state, :initial => :none do
    event :sent do
      transition [:none, :draft] => :sent
    end
    event :draft do
      transition :none => :draft
    end
    event :remove do
      transition all => :deleted
    end
  end
 
  state_machine :received_state, :initial => :none, :namespace => 'message' do
    event :sent do
      transition :none => :unread
    end
    event :read do
      transition :unread => :read
    end
    event :unread do
      transition :read => :unread
    end
    event :archive do
      transition all - [:deleted] => :archived
    end
    event :remove do
      transition all => :deleted
    end
  end
end
 
# == Schema Information
# Schema version: 20090604140050
#
# Table name: messages
#
# id :integer not null, primary key
# from_id :integer not null
# to_id :integer not null
# parent_id :integer
# subject :string(255) not null
# body :text not null
# received_state :string(255) default("unread"), not null
# sent_state :string(255) default("draft"), not null
# created_at :datetime
# updated_at :datetime
#