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