5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-24 14:46:21 +00:00

feat: usar mixins para poder reciclar comportamiento #14433
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
f 2023-10-06 10:44:21 -03:00
parent 9cb2850a13
commit 805225a093
No known key found for this signature in database
5 changed files with 99 additions and 0 deletions

View file

@ -0,0 +1,25 @@
# frozen_string_literal: true
module Metadata
# Mixin para campos que no se pueden cifrar
module AlwaysPublicConcern
extend ActiveSupport::Concern
included do
# Siempre son públicos
#
# @return [Boolean]
def private?
false
end
private
def decrypt(value)
raise NotImplementedError, 'Este atributo no se cifra'
end
alias_method :encrypt, :decrypt
end
end
end

View file

@ -0,0 +1,17 @@
# frozen_string_literal: true
module Metadata
# Mixin para campos que son el contenido de un documento
module ContentConcern
extend ActiveSupport::Concern
included do
# Son parte del contenido
#
# @return [Boolean]
def front_matter?
false
end
end
end
end

View file

@ -0,0 +1,17 @@
# frozen_string_literal: true
module Metadata
# Mixin para campos que son el encabezado de un documento
module FrontMatterConcern
extend ActiveSupport::Concern
included do
# Son parte del encabezado
#
# @return [Boolean]
def front_matter?
true
end
end
end
end

View file

@ -0,0 +1,20 @@
# frozen_string_literal: true
module Metadata
# Mixin para generar atributos indexables
module IndexableConcern
extend ActiveSupport::Concern
included do
# Siempre indexar, a menos que sea un campo privado
#
# @return [Boolean]
def indexable?
true && !private?
end
# Por defecto los valores indexables son el valor actual
alias_method :indexable_values, :value
end
end
end

View file

@ -0,0 +1,20 @@
# frozen_string_literal: true
module Metadata
# Mixin para nunca generar atributos indexables
module NonIndexableConcern
extend ActiveSupport::Concern
included do
# Nunca
def indexable?
false
end
# Lanzar un error para poder enterarnos de la inconsistencia
def indexable_values
raise NotImplementedError, 'Este atributo no es indexable'
end
end
end
end