-
-
Notifications
You must be signed in to change notification settings - Fork 7k
/
adapter.rb
25 lines (19 loc) · 933 Bytes
/
adapter.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
# frozen_string_literal: true
class ActivityPub::Adapter < ActiveModelSerializers::Adapter::Base
include ContextHelper
def self.default_key_transform
:camel_lower
end
def self.transform_key_casing!(value, _options)
ActivityPub::CaseTransform.camel_lower(value)
end
def serializable_hash(options = nil)
named_contexts = { activitystreams: NAMED_CONTEXT_MAP['activitystreams'] }
context_extensions = {}
options = serialization_options(options)
serialized_hash = serializer.serializable_hash(options.merge(named_contexts: named_contexts, context_extensions: context_extensions))
serialized_hash = serialized_hash.select { |k, _| options[:fields].include?(k) } if options[:fields]
serialized_hash = self.class.transform_key_casing!(serialized_hash, instance_options)
{ '@context': serialized_context(named_contexts, context_extensions) }.merge(serialized_hash)
end
end