profile_data_export.rb
1.18 KB
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
module ProfileDataExport
include PersonDataExport
include CommunityDataExport
include ArticleDataExport
include EnterpriseDataExport
def attr_to_hash profile
attrs = profile_attr_to_hash profile
attrs = attrs.merge(self.send("#{profile.type.underscore}_attr_to_hash", profile))
attrs
end
private
def profile_attr_to_hash profile
attrs = {
"type" => profile.type.to_s,
"data" => {
"id" => profile.id,
"identifier" => profile.identifier,
"name" => profile.name,
"description" => profile.description
}
}
attrs['articles-count'] = profile.articles.count
attrs['articles'] = []
profile.articles.each do |article|
attrs['articles'] << article_attr_to_hash(article)
end
attrs['activities-count'] = profile.activities.count
attrs['activities'] = profile_activities_attrs(profile)
attrs
end
def profile_activities_attrs profile
attrs = []
ids = profile.activities.collect { |activity| activity.id }
ActionTracker::Record.find(ids).collect { |activity|
attrs << {
'verb' => activity.verb,
'params' => activity.params
}
}
attrs
end
end