2019-11-01 22:51:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Un campo de orden
|
|
|
|
class MetadataOrder < MetadataTemplate
|
2023-10-06 13:53:19 +00:00
|
|
|
include Metadata::NonIndexableConcern
|
|
|
|
include Metadata::AlwaysPublicConcern
|
|
|
|
|
2019-12-11 20:05:31 +00:00
|
|
|
# El valor según la posición del post en la relación ordenada por
|
|
|
|
# fecha, a fecha más alta, posición más alta
|
2023-10-06 13:53:19 +00:00
|
|
|
#
|
|
|
|
# @return [Integer]
|
2019-11-01 22:51:56 +00:00
|
|
|
def default_value
|
2020-11-11 18:29:12 +00:00
|
|
|
super || site.posts(lang: lang).sort_by(:date).index(post)
|
2019-11-01 22:51:56 +00:00
|
|
|
end
|
2020-02-12 21:24:54 +00:00
|
|
|
|
2023-10-06 13:53:19 +00:00
|
|
|
# Convertir el valor en un entero
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
2020-02-12 21:24:54 +00:00
|
|
|
def save
|
2020-11-09 23:01:27 +00:00
|
|
|
return true unless changed?
|
|
|
|
|
2020-02-12 21:24:54 +00:00
|
|
|
self[:value] = value.to_i
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
2019-11-01 22:51:56 +00:00
|
|
|
end
|