From 3cd483bb7934b314259540358d2f46888428cfb9 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 2 Feb 2024 12:41:44 -0300 Subject: [PATCH] feat: poder obtener la ubicacion a partir de la key --- .../active_storage/service/jekyll_service.rb | 18 +++++++++++++++++- app/models/metadata_file.rb | 2 +- app/models/site/index.rb | 4 ++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/lib/active_storage/service/jekyll_service.rb b/app/lib/active_storage/service/jekyll_service.rb index b33ccf4d..584bf06c 100644 --- a/app/lib/active_storage/service/jekyll_service.rb +++ b/app/lib/active_storage/service/jekyll_service.rb @@ -15,6 +15,14 @@ module ActiveStorage end end + # Obtiene Blob#key desde la ubicaciĆ³n, la inversa de path_for + # + # @param :path [String,Pathname] + # @return [String] + def key_from_path(path) + Pathname.new(path).dirname.basename.to_s + end + # Solo copiamos el archivo si no existe # # @param :key [String] @@ -87,7 +95,15 @@ module ActiveStorage # @param :key [String] # @return [String] def path_for(key) - File.join root, folder_for(key), filename_for(key) + File.join absolute_path_for(key), filename_for(key) + end + + # La ruta absoluta del directorio donde se almacena el archivo + # + # @param :key [String] + # @return [String] + def absolute_path_for(key) + File.join root, folder_for(key) end # @return [Site] diff --git a/app/models/metadata_file.rb b/app/models/metadata_file.rb index 3ac89c9b..e5b2f1ce 100644 --- a/app/models/metadata_file.rb +++ b/app/models/metadata_file.rb @@ -88,7 +88,7 @@ class MetadataFile < MetadataTemplate # # @return [String] def key_from_path - @key_from_path ||= pathname.dirname.basename.to_s + @key_from_path ||= site.blob_service.key_from_path(path: pathname) end def path? diff --git a/app/models/site/index.rb b/app/models/site/index.rb index cfa4030a..b691a855 100644 --- a/app/models/site/index.rb +++ b/app/models/site/index.rb @@ -14,6 +14,10 @@ class Site DELETED_STATUSES = %i[deleted].freeze LOCALE_FROM_PATH = /\A_/.freeze + def blob_service + @blob_service ||= ActiveStorage::Service::JekyllService.build_for_site(site: self) + end + def index_posts! Site.transaction do docs.each(&:index!)