2020-07-02 14:25:04 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-07-21 22:19:40 +00:00
|
|
|
# Almacena el UUID de otro Post y actualiza el valor en el Post
|
|
|
|
# relacionado.
|
2020-07-02 14:25:04 +00:00
|
|
|
class MetadataBelongsTo < MetadataRelatedPosts
|
2023-10-25 18:29:22 +00:00
|
|
|
include Metadata::InverseConcern
|
|
|
|
|
2020-07-02 14:25:04 +00:00
|
|
|
# TODO: Convertir algunos tipos de valores en módulos para poder
|
|
|
|
# implementar varios tipos de campo sin repetir código
|
|
|
|
#
|
|
|
|
# @include MetadataString
|
|
|
|
#
|
|
|
|
# Una string vacía
|
|
|
|
def default_value
|
|
|
|
''
|
|
|
|
end
|
|
|
|
|
2021-07-12 19:52:44 +00:00
|
|
|
# Obtiene el valor desde el documento.
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
def document_value
|
|
|
|
document.data[name.to_s]
|
|
|
|
end
|
|
|
|
|
2021-05-17 20:27:01 +00:00
|
|
|
def indexable_values
|
2023-10-25 18:29:22 +00:00
|
|
|
posts.find_by_post_uuid(value).try(:title)
|
2021-05-17 20:27:01 +00:00
|
|
|
end
|
|
|
|
|
2020-07-02 14:25:04 +00:00
|
|
|
private
|
|
|
|
|
2021-02-11 19:16:25 +00:00
|
|
|
def sanitize(uuid)
|
|
|
|
uuid.to_s.gsub(/[^a-f0-9\-]/i, '')
|
2020-07-02 14:26:00 +00:00
|
|
|
end
|
2020-07-02 14:25:04 +00:00
|
|
|
end
|