5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 06:36:22 +00:00
panel/app/models/activity_pub/concerns/json_ld_concern.rb

33 lines
789 B
Ruby
Raw Normal View History

# 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
rescue NameError
2024-02-20 20:15:43 +00:00
model_name.name.constantize::Generic
end
private
def uri_from_content!
self.uri = content[:id]
end
end
end
end
end