5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 07:06:22 +00:00

chore: rubocop

This commit is contained in:
f 2024-05-24 13:22:28 -03:00
parent 780d26f79a
commit 9c8834facc
No known key found for this signature in database
6 changed files with 22 additions and 24 deletions

View file

@ -2,7 +2,7 @@
# Helpers
module ApplicationHelper
BRACKETS = /[\[\]]/
BRACKETS = /[\[\]]/.freeze
# Devuelve el atributo name de un campo anidado en el formato que
# esperan los helpers *_field

View file

@ -101,6 +101,6 @@ class MetadataBelongsTo < MetadataRelatedPosts
end
def sanitize(uuid)
uuid.to_s.gsub(/[^a-f0-9\-]/i, '')
uuid.to_s.gsub(/[^a-f0-9-]/i, '')
end
end

View file

@ -45,12 +45,12 @@ class MetadataRelatedPosts < MetadataArray
end
def title(post)
"#{post&.title&.value || post&.slug&.value} #{post&.date&.value.strftime('%F')} (#{post.layout.humanized_name})"
"#{post&.title&.value || post&.slug&.value} #{post&.date&.value&.strftime('%F')} (#{post.layout.humanized_name})"
end
def sanitize(uuid)
super(uuid.map do |u|
u.to_s.gsub(/[^a-f0-9\-]/i, '')
u.to_s.gsub(/[^a-f0-9-]/i, '')
end)
end
end

View file

@ -24,8 +24,8 @@ class Post
'created_at' => { 'type' => 'created_at', 'required' => true },
'slug' => { 'type' => 'slug', 'required' => true },
'path' => { 'type' => 'path', 'required' => true },
'locale' => { 'alias' => 'lang' },
}
'locale' => { 'alias' => 'lang' }
}.freeze
class PostError < StandardError; end
class UnknownAttributeError < PostError; end
@ -141,6 +141,7 @@ class Post
src = element.attributes['src']
next unless src&.value&.start_with? 'public/'
file = MetadataFile.new(site: site, post: self, document: document, layout: layout)
file.value['path'] = src.value
@ -202,16 +203,12 @@ class Post
def method_missing(name, *_args)
# Limpiar el nombre del atributo, para que todos los ayudantes
# reciban el método en limpio
unless attribute? name
raise NoMethodError, I18n.t('exceptions.post.no_method', method: name)
end
raise NoMethodError, I18n.t('exceptions.post.no_method', method: name) unless attribute? name
define_singleton_method(name) do
template = layout.metadata[name.to_s]
if template.key?('alias')
return public_send(template['alias'].to_sym)
end
return public_send(template['alias'].to_sym) if template.key?('alias')
@metadata[name] ||=
MetadataFactory.build(document: document,

View file

@ -180,24 +180,24 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
# Si les usuaries modifican o crean una licencia, considerarla
# personalizada en el panel.
def update_site_license!
if site.usuarie?(usuarie) && post.layout.name == :license && !site.licencia.custom?
site.update licencia: Licencia.find_by_icons('custom')
end
return unless site.usuarie?(usuarie) && post.layout.name == :license && !site.licencia.custom?
site.update licencia: Licencia.find_by_icons('custom')
end
# Encuentra todos los posts anidados y los crea o modifica
def create_nested_posts!(post, params)
post.nested_attributes.each do |nested_attribute|
nested_metadata = post[nested_attribute]
# @todo find_or_initialize
nested_post = nested_metadata.has_one || site.posts(lang: post.lang.value).build(layout: nested_metadata.nested)
nested_params = params.require(nested_attribute).permit(nested_post.params).to_hash
nested_metadata = post[nested_attribute]
# @todo find_or_initialize
nested_post = nested_metadata.has_one || site.posts(lang: post.lang.value).build(layout: nested_metadata.nested)
nested_params = params.require(nested_attribute).permit(nested_post.params).to_hash
# Completa la relación 1:1
nested_params[nested_metadata.inverse.to_s] = post.uuid.value
post[nested_attribute].value = nested_post.uuid.value
# Completa la relación 1:1
nested_params[nested_metadata.inverse.to_s] = post.uuid.value
post[nested_attribute].value = nested_post.uuid.value
files << nested_post.path.absolute if nested_post.update(nested_params)
files << nested_post.path.absolute if nested_post.update(nested_params)
end
end
end

View file

@ -126,7 +126,8 @@ module Jekyll
unless spec
I18n.with_locale(locale) do
raise Jekyll::Errors::InvalidThemeName, I18n.t('activerecord.errors.models.site.attributes.design_id.missing_gem', theme: name)
raise Jekyll::Errors::InvalidThemeName,
I18n.t('activerecord.errors.models.site.attributes.design_id.missing_gem', theme: name)
rescue Jekyll::Errors::InvalidThemeName => e
ExceptionNotifier.notify_exception(e, data: { theme: name, site: File.basename(site.source) })
raise