feat: ✨ add core function to validate and sanitize context tags
This commit is contained in:
parent
5ada904040
commit
eca98cda25
1 changed files with 32 additions and 2 deletions
|
@ -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,String>, 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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue