5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-23 01:26:22 +00:00

refactor: llevar un staging de archivos a agregar

This commit is contained in:
f 2024-04-17 18:07:42 -03:00
parent ce3ff1bdab
commit 363e2d8385
No known key found for this signature in database

View file

@ -17,7 +17,9 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
post.slug.value = p[:slug] if p[:slug].present?
end
commit(action: :created, add: update_related_posts) if post.save
update_related_posts
commit(action: :created, add: files) if post.save
update_site_license!
@ -35,7 +37,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
# Los artículos anónimos siempre son borradores
params[:draft] = true
commit(action: :created, add: [post.path.absolute]) if post.update(anon_post_params)
commit(action: :created, add: files) if post.update(anon_post_params)
post
end
@ -48,9 +50,11 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
rm = []
rm << post.path.value_was if post.path.changed?
update_related_posts
# Es importante que el artículo se guarde primero y luego los
# relacionados.
commit(action: :updated, add: update_related_posts, rm: rm)
commit(action: :updated, add: files, rm: rm)
update_site_license!
end
@ -97,6 +101,15 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
private
# Una lista de archivos a modificar
#
# @return [Set]
def files
@files ||= Set.new.tap do |f|
f << post.path.absolute
end
end
def commit(action:, add: [], rm: [])
site.repository.commit(add: add,
rm: rm,
@ -147,8 +160,10 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
end
posts.map do |p|
p.path.absolute if p.save(validate: false)
end.compact << post.path.absolute
next unless p.save(validate: false)
files << p.path.absolute
end
end
# Si les usuaries modifican o crean una licencia, considerarla