Class: ActivityPub::OutboxSerializer

Inherits:
BaseSerializer
  • Object
show all
Defined in:
app/serializers/activitypub/outbox_serializer.rb

Constant Summary

Constants inherited from BaseSerializer

BaseSerializer::CONTEXT

Instance Attribute Summary

Attributes inherited from BaseSerializer

#options

Instance Method Summary collapse

Methods inherited from BaseSerializer

#as_json, #initialize, #to_json

Constructor Details

This class inherits a constructor from ActivityPub::BaseSerializer

Instance Method Details

#dataObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/serializers/activitypub/outbox_serializer.rb', line 3

def data
  result = {
    id: object.id,
    type: type
  }

  result[:totalItems] = total_items if object.size.present?
  result[:next] = object.next if object.next.present?
  result[:prev] = object.prev if object.prev.present?
  result[:part_of] = object.part_of if object.part_of.present?

  result[:first] = object.first if object.first.present?
  result[:last] = object.last if object.last.present?

  result[:items] = items if (!object.items.nil? || page?) && !ordered?
  result[:ordered_items] = items if (!object.items.nil? || page?) && ordered?

  result
end

#itemsObject



35
36
37
# File 'app/serializers/activitypub/outbox_serializer.rb', line 35

def items
  ActivityPub::StorySerializer.list(object.items).data
end

#total_itemsObject



31
32
33
# File 'app/serializers/activitypub/outbox_serializer.rb', line 31

def total_items
  object.size
end

#typeObject



23
24
25
26
27
28
29
# File 'app/serializers/activitypub/outbox_serializer.rb', line 23

def type
  if page?
    ordered? ? 'OrderedCollectionPage' : 'CollectionPage'
  else
    ordered? ? 'OrderedCollection' : 'Collection'
  end
end