2020-05-26 22:26:19 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Los valores de este metadato son artículos en otros idiomas
|
2023-03-22 16:43:13 +00:00
|
|
|
class MetadataLocales < MetadataHasAndBelongsToMany
|
2020-05-26 22:26:19 +00:00
|
|
|
# Todos los valores posibles para cada idioma disponible
|
|
|
|
#
|
|
|
|
# @return { lang: { title: uuid } }
|
|
|
|
def values
|
|
|
|
@values ||= site.locales.map do |locale|
|
2023-03-22 17:26:06 +00:00
|
|
|
[locale, posts.where(lang: locale).map do |post|
|
2023-03-22 16:43:13 +00:00
|
|
|
[title(post), post.uuid.value]
|
2021-03-03 12:43:15 +00:00
|
|
|
end.to_h]
|
2020-11-07 23:51:00 +00:00
|
|
|
end.to_h
|
2020-05-26 22:26:19 +00:00
|
|
|
end
|
2023-03-22 17:26:06 +00:00
|
|
|
|
|
|
|
# Siempre hay una relación inversa
|
|
|
|
#
|
|
|
|
# @return [True]
|
|
|
|
def inverse?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
# El campo inverso se llama igual en el otro post
|
|
|
|
#
|
|
|
|
# @return [Symbol]
|
|
|
|
def inverse
|
|
|
|
:locales
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Obtiene todos los locales distintos a este post
|
|
|
|
#
|
|
|
|
# @return [Array]
|
|
|
|
def other_locales
|
2023-10-06 20:23:55 +00:00
|
|
|
@other_locales ||= site.locales.reject do |other_locale|
|
|
|
|
other_locale.to_s == locale
|
2023-03-22 17:26:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Obtiene todos los posts de los otros locales con el mismo layout
|
|
|
|
#
|
2023-10-06 20:23:55 +00:00
|
|
|
# @return [IndexedPost::ActiveRecord_AssociationRelation]
|
2023-03-22 17:26:06 +00:00
|
|
|
def posts
|
2023-10-06 20:23:55 +00:00
|
|
|
site.indexed_posts(locale: other_locales).where(layout: post.layout.value).where.not(post_id: post.uuid.value)
|
2023-03-22 17:26:06 +00:00
|
|
|
end
|
2020-05-26 22:26:19 +00:00
|
|
|
end
|