mirror of
https://github.com/funamitech/mastodon
synced 2024-12-05 10:18:45 +09:00
d1ecc323e7
Co-authored-by: Puck Meerburg <puck@puck.moe>
26 lines
935 B
Ruby
26 lines
935 B
Ruby
# 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
|