2024-02-20 17:44:52 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityPub
|
|
|
|
module Concerns
|
|
|
|
module JsonLdConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
# Cuando asignamos contenido, obtener la URI si no lo hicimos ya
|
|
|
|
before_save :uri_from_content!, unless: :uri?
|
|
|
|
|
|
|
|
# Obtiene un tipo de actividad a partir del tipo informado
|
|
|
|
#
|
|
|
|
# @param object [Hash]
|
|
|
|
# @return [Activity]
|
|
|
|
def self.type_from(object)
|
2024-02-20 20:15:43 +00:00
|
|
|
raise NameError unless object.is_a?(Hash)
|
|
|
|
|
|
|
|
"#{model_name.name}::#{object[:type].presence || 'Generic'}".constantize
|
2024-02-20 17:44:52 +00:00
|
|
|
rescue NameError
|
2024-02-20 20:15:43 +00:00
|
|
|
model_name.name.constantize::Generic
|
2024-02-20 17:44:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def uri_from_content!
|
|
|
|
self.uri = content[:id]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|