feat: 🔥 oh god
This commit is contained in:
parent
cdb5492bfe
commit
3c7f48016d
30 changed files with 708 additions and 280 deletions
|
@ -53,17 +53,7 @@ module Comfpile
|
|||
tags.empty?
|
||||
end
|
||||
|
||||
def hash
|
||||
@tag.hash
|
||||
end
|
||||
|
||||
def eql?(other)
|
||||
if(other.is_a? Symbol)
|
||||
@tag.eql? other
|
||||
elsif(other.is_a? ContextTag)
|
||||
@tag.eql? other.tag
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
|
@ -119,78 +109,88 @@ module Comfpile
|
|||
raise ArgumentError, "Attempted to set child-parameter of another parameter!"
|
||||
end
|
||||
|
||||
current_hash[key[-1]] = value
|
||||
|
||||
value
|
||||
end
|
||||
alias set []=
|
||||
|
||||
def set_flag(key, value)
|
||||
set resolve_key(key).append(value), true
|
||||
end
|
||||
def get_flags(key)
|
||||
(@config_options&.dig(*resolve_key(key)) || {}).keys
|
||||
return @provider.provide_context(new_keys)
|
||||
end
|
||||
|
||||
def dig(arg0, *args)
|
||||
@config_options&.dig(arg0, *args)
|
||||
end
|
||||
|
||||
def append(key, value)
|
||||
key = resolve_key key
|
||||
array = @config_options&.dig(*key)
|
||||
|
||||
if array.nil?
|
||||
array = set key, []
|
||||
end
|
||||
|
||||
raise ArgumentError, "Attempted to append to a non-list parameter!" unless array.is_a? Array
|
||||
|
||||
array << value
|
||||
end
|
||||
alias append_to append
|
||||
|
||||
def assert(orig_key, value)
|
||||
key = resolve_key orig_key
|
||||
current_value = @config_options&.dig(*key)
|
||||
|
||||
if current_value.nil?
|
||||
set key, value
|
||||
elsif current_value != value
|
||||
raise ArgumentError, "Config key assertion failed! #{orig_key} should be #{value}, is #{current_value}!"
|
||||
end
|
||||
end
|
||||
|
||||
def build_config
|
||||
@config_options = nil
|
||||
|
||||
@seeder_blocks.sort { |block| block[:priority] }.each do |block|
|
||||
self.instance_exec(block, &block[:block])
|
||||
end
|
||||
|
||||
self.freeze
|
||||
def to_s
|
||||
"CTX[" + @context_symbol.to_s + "]"
|
||||
end
|
||||
alias inspect to_s
|
||||
end
|
||||
|
||||
class ContextConfigContainer
|
||||
|
||||
class ContextKeyProvider
|
||||
def initialize
|
||||
@context_configs_seeds = []
|
||||
@known_context_keys = Hash.new
|
||||
end
|
||||
|
||||
def find_seeds_for(context_tag)
|
||||
out = []
|
||||
def symbol_to_keys(symbol)
|
||||
raise ArgumentError, 'Input symbol needs to be a Symbol!' unless symbol.is_a? Symbol
|
||||
|
||||
@context_configs_seeds.each do |seed|
|
||||
seed_tags = seed[:context_tags]
|
||||
|
||||
seed_tags.each do |tag|
|
||||
out_keys = Hash.new
|
||||
|
||||
symbol.to_s.split(';').each do |key|
|
||||
if key =~ /(?<key>[^=]+)=(?<value>[^=]+)/
|
||||
out_keys[$~['key'].to_sym] = $~['value'].to_s
|
||||
else
|
||||
out_keys[key.to_sym] = true
|
||||
end
|
||||
end
|
||||
|
||||
out_keys
|
||||
end
|
||||
|
||||
def add_to_config(context_config)
|
||||
raise ArgumentError, "No context supplied!" unless context_config.is_a? ContextConfig
|
||||
def sanitize_keys(keys)
|
||||
out_keys = Hash.new
|
||||
|
||||
keys.each do |key, value|
|
||||
if value.is_a? TrueClass
|
||||
out_keys[key.to_sym] = true
|
||||
elsif (not value.nil?) and (not value.is_a? FalseClass)
|
||||
out_keys[key.to_sym] = value.to_s
|
||||
end
|
||||
end
|
||||
|
||||
out_keys
|
||||
end
|
||||
|
||||
def keys_to_symbol(keys)
|
||||
raise ArgumentError, 'Keys needs to be a Hash!' unless keys.is_a? Hash
|
||||
|
||||
keys.keys.sort.map do |key|
|
||||
value = keys[key]
|
||||
|
||||
if value.is_a? TrueClass
|
||||
key.to_s
|
||||
elsif value.is_a? FalseClass
|
||||
nil
|
||||
else
|
||||
"#{key}=#{value}"
|
||||
end
|
||||
end.compact.join(';').to_sym
|
||||
end
|
||||
|
||||
def provide_context(ctx)
|
||||
return ctx if ctx.is_a? ContextKey
|
||||
|
||||
orig_ctx = ctx
|
||||
|
||||
return @known_context_keys[ctx] if @known_context_keys.include? ctx
|
||||
|
||||
ctx = symbol_to_keys(ctx) if ctx.is_a? Symbol
|
||||
ctx = sanitize_keys(ctx)
|
||||
|
||||
ctx_symbol = keys_to_symbol(ctx)
|
||||
|
||||
if @known_context_keys.include? ctx
|
||||
existing_ctx = @known_context_keys[ctx]
|
||||
@known_context_keys[orig_ctx] = existing_ctx
|
||||
return existing_ctx
|
||||
end
|
||||
|
||||
new_ctx = ContextKey.new(self, ctx, ctx_symbol)
|
||||
|
||||
@known_context_keys[ctx] = new_ctx
|
||||
@known_context_keys[ctx_symbol] = new_ctx
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue