5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 09:06:21 +00:00

no tener que definir to_param en cada Metadata

This commit is contained in:
f 2020-07-21 19:34:15 -03:00
parent 2f2cc0e3c3
commit 0d703d0d43
9 changed files with 14 additions and 28 deletions

View file

@ -7,10 +7,6 @@ class MetadataArray < MetadataTemplate
[]
end
def to_param
{ name => [] }
end
private
def sanitize(values)

View file

@ -13,11 +13,6 @@ class MetadataBelongsTo < MetadataRelatedPosts
''
end
# @see MetadataTemplate
def to_param
name
end
def validate
super

View file

@ -10,11 +10,9 @@ class MetadataDocumentDate < MetadataTemplate
# El valor puede ser un Date, Time o una String en el formato
# "yyyy-mm-dd"
def value
return self[:value] = document.date || default_value if self[:value].nil?
return (self[:value] = document.date || default_value) if self[:value].nil?
if self[:value].is_a? String
self[:value] = Date.iso8601(self[:value]).to_time
end
self[:value] = Date.iso8601(self[:value]).to_time if self[:value].is_a? String
self[:value]
end

View file

@ -50,10 +50,6 @@ class MetadataFile < MetadataTemplate
true
end
def to_param
{ name => %i[description path] }
end
# Almacena el archivo en el sitio y lo devuelve
#
# @return ActiveStorage::Attachment

View file

@ -10,10 +10,6 @@ class MetadataGeo < MetadataTemplate
value == default_value
end
def to_param
{ name => %i[lat lng] }
end
def save
return true if empty?

View file

@ -7,7 +7,7 @@ class MetadataLang < MetadataTemplate
end
def value
self[:value] || document.collection.label || default_value
self[:value] ||= document.collection.label || default_value
end
def values

View file

@ -9,6 +9,7 @@ class MetadataLocales < MetadataTemplate
# Todos los valores posibles para cada idioma disponible
#
# TODO: Optimizar?
# TODO: Mantener sincronizados
#
# @return { lang: { title: uuid } }
def values
@ -20,8 +21,4 @@ class MetadataLocales < MetadataTemplate
}
end.inject(:merge)
end
def to_param
{ name => [] }
end
end

View file

@ -33,7 +33,7 @@ class MetadataSlug < MetadataTemplate
end
def value
self[:value] || document.data.fetch('slug', default_value)
self[:value] ||= document.data.fetch('slug', default_value)
end
private

View file

@ -53,8 +53,16 @@ MetadataTemplate = Struct.new(:site, :document, :name, :label, :type,
errors.empty?
end
# Usa el valor por defecto para generar el formato de StrongParam
# necesario.
#
# @return [Symbol,Hash]
def to_param
name
case default_value
when Hash then { name => default_value.keys.map(&:to_sym) }
when Array then { name => [] }
else name
end
end
def to_s