5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 09:06:21 +00:00

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 # TODO: Aplicar rate_limit
def create def create
csp = CspReport.new(csp_report_params.to_h.map do |k, v| csp = CspReport.new(csp_report_params.to_h.map do |k, v|
{ k.tr('-', '_') => v } [k.tr('-', '_'), v]
end.inject(&:merge)) end.to_h)
csp.id = SecureRandom.uuid csp.id = SecureRandom.uuid
csp.save csp.save

View file

@ -61,13 +61,13 @@ class MetadataEvent < MetadataTemplate
self[:value] = %w[dtstart dtend].map do |dt| self[:value] = %w[dtstart dtend].map do |dt|
time = hash.dig(dt, 'time') time = hash.dig(dt, 'time')
{ [
dt => { dt, {
'zone' => hash.dig(dt, 'zone'), 'zone' => hash.dig(dt, 'zone'),
'date' => Date.parse(hash.dig(dt, 'date')).to_s, 'date' => Date.parse(hash.dig(dt, 'date')).to_s,
'time' => time.blank? ? '00:00' : time 'time' => time.blank? ? '00:00' : time
} }
} ]
end.inject(:merge) end.to_h
end end
end end

View file

@ -14,11 +14,9 @@ class MetadataLocales < MetadataTemplate
# @return { lang: { title: uuid } } # @return { lang: { title: uuid } }
def values def values
@values ||= site.locales.map do |locale| @values ||= site.locales.map do |locale|
{ [locale.to_sym, site.posts(lang: locale).map do |post|
locale.to_sym => site.posts(lang: locale).map do |post| [post.title.value, post.uuid.value]
{ post.title.value => post.uuid.value } end.to_h]
end.inject(:merge) end.to_h
}
end.inject(:merge)
end end
end end

View file

@ -4,7 +4,7 @@
class MetadataPredefinedArray < MetadataArray class MetadataPredefinedArray < MetadataArray
def values def values
@values ||= layout[:metadata][name]['values'].map do |k, v| @values ||= layout[:metadata][name]['values'].map do |k, v|
{ v[I18n.locale.to_s] => k } [v[I18n.locale.to_s], k]
end.inject(&:merge) end.to_h
end end
end end

View file

@ -4,10 +4,11 @@
# idioma que el actual, para usar con input-map.js # idioma que el actual, para usar con input-map.js
class MetadataRelatedPosts < MetadataArray class MetadataRelatedPosts < MetadataArray
# Genera un Hash de { title | slug => uuid } # Genera un Hash de { title | slug => uuid }
# @return [Hash]
def values def values
@values ||= posts.map do |p| @values ||= posts.map do |p|
{ title(p) => p.uuid.value } [title(p), p.uuid.value]
end.inject(:merge) end.to_h
end end
# Las relaciones nunca son privadas # Las relaciones nunca son privadas

View file

@ -205,8 +205,8 @@ class Post < OpenStruct
next if template.empty? next if template.empty?
{ metadata.to_s => template.value } [metadata.to_s, template.value]
end.compact.inject(:merge) end.compact.to_h
# TODO: Convertir a Metadata? # TODO: Convertir a Metadata?
# Asegurarse que haya un layout # Asegurarse que haya un layout

View file

@ -265,10 +265,8 @@ class Site < ApplicationRecord
# NoMethodError # NoMethodError
@layouts_struct ||= Struct.new(*layout_keys, keyword_init: true) @layouts_struct ||= Struct.new(*layout_keys, keyword_init: true)
@layouts ||= @layouts_struct.new(**data.fetch('layouts', {}).map do |name, metadata| @layouts ||= @layouts_struct.new(**data.fetch('layouts', {}).map do |name, metadata|
{ name.to_sym => Layout.new(site: self, [name.to_sym, Layout.new(site: self, name: name.to_sym, metadata: metadata.with_indifferent_access)]
name: name.to_sym, end.to_h)
metadata: metadata.with_indifferent_access) }
end.inject(:merge))
end end
def layout_keys def layout_keys