adapter.rb 935 B

12345678910111213141516171819202122232425
  1. # frozen_string_literal: true
  2. class ActivityPub::Adapter < ActiveModelSerializers::Adapter::Base
  3. include ContextHelper
  4. def self.default_key_transform
  5. :camel_lower
  6. end
  7. def self.transform_key_casing!(value, _options)
  8. ActivityPub::CaseTransform.camel_lower(value)
  9. end
  10. def serializable_hash(options = nil)
  11. named_contexts = { activitystreams: NAMED_CONTEXT_MAP['activitystreams'] }
  12. context_extensions = {}
  13. options = serialization_options(options)
  14. serialized_hash = serializer.serializable_hash(options.merge(named_contexts: named_contexts, context_extensions: context_extensions))
  15. serialized_hash = serialized_hash.select { |k, _| options[:fields].include?(k) } if options[:fields]
  16. serialized_hash = self.class.transform_key_casing!(serialized_hash, instance_options)
  17. { '@context' => serialized_context(named_contexts, context_extensions) }.merge(serialized_hash)
  18. end
  19. end