garantizar que devolvemos un hash

This commit is contained in:
f 2020-11-07 20:51:00 -03:00
parent d9241622b3
commit c1dff95257
7 changed files with 19 additions and 22 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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