From 1878186c4f4e3e20008236f47f436a82a25bbd2d Mon Sep 17 00:00:00 2001 From: David Bailey Date: Thu, 20 Apr 2023 09:48:22 +0200 Subject: [PATCH] feat: :sparkles: add context tag handling to core's crafting functions --- lib/comfpile/core.rb | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/comfpile/core.rb b/lib/comfpile/core.rb index 172d71d..883bccd 100644 --- a/lib/comfpile/core.rb +++ b/lib/comfpile/core.rb @@ -49,6 +49,10 @@ module Comfpile end end + def find_artefact(stage, file = :none, context = :default) + context = sanitize_context(context) + + @artefacts.dig(context, stage, file) end # Create or find a new artefact. @@ -66,17 +70,20 @@ module Comfpile # # @return [Comfpile::Artefact, nil] Found or created artefact, or nil if nothing could be done # - def craft_artefact(stage, file = :none) - artefact = find_artefact(stage, file) + def craft_artefact(stage, file = :none, context = :default) + context = sanitize_context(context) + + artefact = find_artefact(stage, file, context) return artefact unless artefact.nil? @artefact_engines.each do |engine| - artefact = engine.craft stage, file + artefact = engine.craft stage, file, context if artefact - @artefacts[stage] ||= {} - @artefacts[stage][file] = artefact + @artefacts[context] ||= {} + @artefacts[context][stage] ||= {} + @artefacts[context][stage][file] = artefact @processing_stack.push artefact @@ -87,13 +94,16 @@ module Comfpile nil end - def add_artefact(stage, file = :none, engine: nil, artefact_class: Comfpile::Artefact) - return unless find_artefact(stage, file).nil? + def add_artefact(stage, file = :none, context = :default, engine: nil, artefact_class: Comfpile::Artefact) + context = sanitize_context context - a = Artefact.new(self, engine, stage, file); + return unless find_artefact(stage, file, context).nil? + + a = Artefact.new(self, engine, stage, file, context); - @artefacts[stage] ||= {} - @artefacts[stage][file] = a + @artefacts[context] ||= {} + @artefacts[context][stage] ||= {} + @artefacts[context][stage][file] = a yield(a) if block_given?