2017-07-15 01:01:39 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityPub::Adapter < ActiveModelSerializers::Adapter::Base
|
2022-02-03 13:07:29 +00:00
|
|
|
include ContextHelper
|
2017-09-02 12:01:23 +00:00
|
|
|
|
2017-07-15 01:01:39 +00:00
|
|
|
def self.default_key_transform
|
|
|
|
:camel_lower
|
|
|
|
end
|
|
|
|
|
2017-08-12 15:41:03 +00:00
|
|
|
def self.transform_key_casing!(value, _options)
|
|
|
|
ActivityPub::CaseTransform.camel_lower(value)
|
|
|
|
end
|
|
|
|
|
2017-07-15 01:01:39 +00:00
|
|
|
def serializable_hash(options = nil)
|
2022-02-03 13:07:29 +00:00
|
|
|
named_contexts = { activitystreams: NAMED_CONTEXT_MAP['activitystreams'] }
|
2019-09-03 20:52:32 +00:00
|
|
|
context_extensions = {}
|
2019-12-02 17:25:43 +00:00
|
|
|
|
2019-03-27 14:55:23 +00:00
|
|
|
options = serialization_options(options)
|
2019-09-03 20:52:32 +00:00
|
|
|
serialized_hash = serializer.serializable_hash(options.merge(named_contexts: named_contexts, context_extensions: context_extensions))
|
2019-07-11 18:11:09 +00:00
|
|
|
serialized_hash = serialized_hash.select { |k, _| options[:fields].include?(k) } if options[:fields]
|
2019-03-27 14:55:23 +00:00
|
|
|
serialized_hash = self.class.transform_key_casing!(serialized_hash, instance_options)
|
|
|
|
|
2019-09-03 20:52:32 +00:00
|
|
|
{ '@context' => serialized_context(named_contexts, context_extensions) }.merge(serialized_hash)
|
2019-03-27 14:55:23 +00:00
|
|
|
end
|
2017-07-15 01:01:39 +00:00
|
|
|
end
|