/
relayable.rb
46 lines (35 loc) · 1.09 KB
/
relayable.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 Federated
class Relayable < ActiveRecord::Base
self.abstract_class = true
#crazy ordering issues - DEATH TO ROXML
include Diaspora::Federated::Base
include Diaspora::Guid
#seriously, don't try to move this shit around until you have killed ROXML
xml_attr :target_type
include Diaspora::Relayable
xml_attr :diaspora_handle
belongs_to :target, :polymorphic => true
belongs_to :author, :class_name => 'Person'
#end crazy ordering issues
validates_uniqueness_of :target_id, :scope => [:target_type, :author_id]
validates :parent, :presence => true #should be in relayable (pending on fixing Message)
def diaspora_handle
self.author.diaspora_handle
end
def diaspora_handle=(nh)
self.author = Person.find_or_fetch_by_identifier(nh)
end
def parent_class
self.target_type.constantize
end
def parent
self.target
end
def parent= parent
self.target = parent
end
def fetch_parent guid
Diaspora::Fetcher::Single.find_or_fetch_from_remote guid, diaspora_handle
end
end
end