diff --git a/lib/comfpile/core.rb b/lib/comfpile/core.rb index f697634..172d71d 100644 --- a/lib/comfpile/core.rb +++ b/lib/comfpile/core.rb @@ -13,12 +13,42 @@ module Comfpile # First query is stage, second filename. @artefacts = {} + @valid_contexts = {} + # Stack-style processing queue for item processing @processing_stack = [] end - def find_artefact(stage, file = :none) - @artefacts.dig(stage, file) + # Sanitize and unify context tags. + # This function will take either an array of tags, or a symbol, + # and sanitize and unify it to match a predictable context tag + # format. + # + # Context tags are symbols containing a list of unique configs + # types to use, separated by underscore ('_') + # + # @param [Array, Symbol] context The context to + # sanitize + # + # @return [Symbol] Sanitized context. Unique, sorted list + # of tags, joined into a Symbol. + # + def sanitize_context(context) + if context.nil? + return :default + elsif context.is_a? Array + new_context = context.uniq.sort.join('_').to_sym + @valid_contexts[new_context] = true + + return new_context + elsif context.is_a? Symbol + return context if @valid_contexts[context] + return sanitize_context(context.to_s.split('_')) + else + raise ArgumentError, "Unknown context key type supplied!" + end + end + end # Create or find a new artefact.