mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-24 11:46:22 +00:00
feat: usar mixins para poder reciclar comportamiento #14433
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
9cb2850a13
commit
805225a093
5 changed files with 99 additions and 0 deletions
25
app/models/concerns/metadata/always_public_concern.rb
Normal file
25
app/models/concerns/metadata/always_public_concern.rb
Normal 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
|
17
app/models/concerns/metadata/content_concern.rb
Normal file
17
app/models/concerns/metadata/content_concern.rb
Normal 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
|
17
app/models/concerns/metadata/front_matter_concern.rb
Normal file
17
app/models/concerns/metadata/front_matter_concern.rb
Normal 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
|
20
app/models/concerns/metadata/indexable_concern.rb
Normal file
20
app/models/concerns/metadata/indexable_concern.rb
Normal 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
|
20
app/models/concerns/metadata/non_indexable_concern.rb
Normal file
20
app/models/concerns/metadata/non_indexable_concern.rb
Normal 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
|
Loading…
Reference in a new issue