mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-23 05:26:22 +00:00
33 lines
777 B
Ruby
33 lines
777 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
class ActivityPub
|
||
|
module Concerns
|
||
|
module JsonLdConcern
|
||
|
extend ActiveSupport::Concern
|
||
|
|
||
|
included do
|
||
|
validates :uri, presence: true, uniqueness: true
|
||
|
|
||
|
# 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)
|
||
|
"#{self.class.name}::#{object[:type].presence || 'Generic'}".constantize
|
||
|
rescue NameError
|
||
|
self.class::Generic
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def uri_from_content!
|
||
|
self.uri = content[:id]
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|