From c1dff952575e00d53afc9619bf83d6895946fb11 Mon Sep 17 00:00:00 2001 From: f Date: Sat, 7 Nov 2020 20:51:00 -0300 Subject: [PATCH] garantizar que devolvemos un hash --- app/controllers/api/v1/csp_reports_controller.rb | 4 ++-- app/models/metadata_event.rb | 8 ++++---- app/models/metadata_locales.rb | 10 ++++------ app/models/metadata_predefined_array.rb | 4 ++-- app/models/metadata_related_posts.rb | 5 +++-- app/models/post.rb | 4 ++-- app/models/site.rb | 6 ++---- 7 files changed, 19 insertions(+), 22 deletions(-) diff --git a/app/controllers/api/v1/csp_reports_controller.rb b/app/controllers/api/v1/csp_reports_controller.rb index 1c1ef0a0..bc6cfae0 100644 --- a/app/controllers/api/v1/csp_reports_controller.rb +++ b/app/controllers/api/v1/csp_reports_controller.rb @@ -12,8 +12,8 @@ module Api # TODO: Aplicar rate_limit def create csp = CspReport.new(csp_report_params.to_h.map do |k, v| - { k.tr('-', '_') => v } - end.inject(&:merge)) + [k.tr('-', '_'), v] + end.to_h) csp.id = SecureRandom.uuid csp.save diff --git a/app/models/metadata_event.rb b/app/models/metadata_event.rb index 89007dd2..3213d87e 100644 --- a/app/models/metadata_event.rb +++ b/app/models/metadata_event.rb @@ -61,13 +61,13 @@ class MetadataEvent < MetadataTemplate self[:value] = %w[dtstart dtend].map do |dt| time = hash.dig(dt, 'time') - { - dt => { + [ + dt, { 'zone' => hash.dig(dt, 'zone'), 'date' => Date.parse(hash.dig(dt, 'date')).to_s, 'time' => time.blank? ? '00:00' : time } - } - end.inject(:merge) + ] + end.to_h end end diff --git a/app/models/metadata_locales.rb b/app/models/metadata_locales.rb index 6498ed77..89581107 100644 --- a/app/models/metadata_locales.rb +++ b/app/models/metadata_locales.rb @@ -14,11 +14,9 @@ class MetadataLocales < MetadataTemplate # @return { lang: { title: uuid } } def values @values ||= site.locales.map do |locale| - { - locale.to_sym => site.posts(lang: locale).map do |post| - { post.title.value => post.uuid.value } - end.inject(:merge) - } - end.inject(:merge) + [locale.to_sym, site.posts(lang: locale).map do |post| + [post.title.value, post.uuid.value] + end.to_h] + end.to_h end end diff --git a/app/models/metadata_predefined_array.rb b/app/models/metadata_predefined_array.rb index a6e2105f..829a8a28 100644 --- a/app/models/metadata_predefined_array.rb +++ b/app/models/metadata_predefined_array.rb @@ -4,7 +4,7 @@ class MetadataPredefinedArray < MetadataArray def values @values ||= layout[:metadata][name]['values'].map do |k, v| - { v[I18n.locale.to_s] => k } - end.inject(&:merge) + [v[I18n.locale.to_s], k] + end.to_h end end diff --git a/app/models/metadata_related_posts.rb b/app/models/metadata_related_posts.rb index e38538a8..5148a9fe 100644 --- a/app/models/metadata_related_posts.rb +++ b/app/models/metadata_related_posts.rb @@ -4,10 +4,11 @@ # idioma que el actual, para usar con input-map.js class MetadataRelatedPosts < MetadataArray # Genera un Hash de { title | slug => uuid } + # @return [Hash] def values @values ||= posts.map do |p| - { title(p) => p.uuid.value } - end.inject(:merge) + [title(p), p.uuid.value] + end.to_h end # Las relaciones nunca son privadas diff --git a/app/models/post.rb b/app/models/post.rb index c238ece1..f43c02eb 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -205,8 +205,8 @@ class Post < OpenStruct next if template.empty? - { metadata.to_s => template.value } - end.compact.inject(:merge) + [metadata.to_s, template.value] + end.compact.to_h # TODO: Convertir a Metadata? # Asegurarse que haya un layout diff --git a/app/models/site.rb b/app/models/site.rb index daa83c4c..38645a38 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -265,10 +265,8 @@ class Site < ApplicationRecord # NoMethodError @layouts_struct ||= Struct.new(*layout_keys, keyword_init: true) @layouts ||= @layouts_struct.new(**data.fetch('layouts', {}).map do |name, metadata| - { name.to_sym => Layout.new(site: self, - name: name.to_sym, - metadata: metadata.with_indifferent_access) } - end.inject(:merge)) + [name.to_sym, Layout.new(site: self, name: name.to_sym, metadata: metadata.with_indifferent_access)] + end.to_h) end def layout_keys