From 9c8834faccba6722e91ef8b6c69ba098401c007c Mon Sep 17 00:00:00 2001 From: f Date: Fri, 24 May 2024 13:22:28 -0300 Subject: [PATCH] chore: rubocop --- app/helpers/application_helper.rb | 2 +- app/models/metadata_belongs_to.rb | 2 +- app/models/metadata_related_posts.rb | 4 ++-- app/models/post.rb | 13 +++++-------- app/services/post_service.rb | 22 +++++++++++----------- config/initializers/core_extensions.rb | 3 ++- 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c83b2894..ba92f626 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/models/metadata_belongs_to.rb b/app/models/metadata_belongs_to.rb index 7dec4f94..16b0e2ed 100644 --- a/app/models/metadata_belongs_to.rb +++ b/app/models/metadata_belongs_to.rb @@ -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 diff --git a/app/models/metadata_related_posts.rb b/app/models/metadata_related_posts.rb index 9e84c446..6ca09f7d 100644 --- a/app/models/metadata_related_posts.rb +++ b/app/models/metadata_related_posts.rb @@ -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 diff --git a/app/models/post.rb b/app/models/post.rb index 64669524..a1758464 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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, diff --git a/app/services/post_service.rb b/app/services/post_service.rb index 628d1b63..4d32cba9 100644 --- a/app/services/post_service.rb +++ b/app/services/post_service.rb @@ -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 diff --git a/config/initializers/core_extensions.rb b/config/initializers/core_extensions.rb index 6861da45..024a26ab 100644 --- a/config/initializers/core_extensions.rb +++ b/config/initializers/core_extensions.rb @@ -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