Class: ActivityPub::BaseSerializer

Inherits:
Granola::Serializer
  • Object
show all
Includes:
RoutingHelper
Defined in:
app/serializers/activitypub/base_serializer.rb

Constant Summary collapse

CONTEXT =
[
  'https://www.w3.org/ns/activitystreams',
  'https://w3id.org/security/v1',

  {
    'Hashtag' => 'as:Hashtag'
  }, {
    'votes' => {
      '@id'   => 'as:votes',
      '@type' => '@id'
    }
  }
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, options = {}) ⇒ BaseSerializer

Returns a new instance of BaseSerializer.



21
22
23
24
# File 'app/serializers/activitypub/base_serializer.rb', line 21

def initialize(object, options = {})
  @options = options
  super(object)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



19
20
21
# File 'app/serializers/activitypub/base_serializer.rb', line 19

def options
  @options
end

Instance Method Details

#as_json(opts = {}) ⇒ Object



26
27
28
29
30
31
32
33
# File 'app/serializers/activitypub/base_serializer.rb', line 26

def as_json(opts = {})
  options.merge!(opts)

  json = data
  json['@context'] = CONTEXT if options[:with_context]

  json
end

#to_json(opts = {}) ⇒ Object



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

def to_json(opts = {})
  Oj.dump(as_json(opts))
end