<commit_before>
module CORL
module Mixin
module Lookup

  #-----------------------------------------------------------------------------
  # Facter lookup
  
  def facts
    fact_map = {}
    Facter.list.each do |name|
      fact_map[name] = Facter.value(name)
    end
    fact_map
  end
  
  def fact(name)
    Facter.value(name)
  end
  
  #-----------------------------------------------------------------------------
  # Hiera configuration
  
  @@hiera = nil
  
  #---
  
  def hiera_config
    config_file = CORL.value(:hiera_config_file, nil)
    config      = {}

    if config_file && File.exist?(config_file)
      config = Hiera::Config.load(config_file)
    end
    config[:logger] = :corl
    
    results = CORL.config(:hiera_config, { :config => config })
    results[:config]
  end
  
  #---

  def hiera
    @@hiera = Hiera.new(:config => hiera_config) if @@hiera.nil?
    @@hiera
  end
  
  #-----------------------------------------------------------------------------
  # Configuration lookup interface
      
  def config_initialized?
    ready = false
    if CORL.admin? && hiera && network_path = fact(:corl_network)
      ready = File.directory?(network_path) && File.directory?(File.join(network_path, 'config')) ? true : false
    end
    ready
  end
  
  #---
    
  def lookup(properties, default = nil, options = {})
    config      = Config.ensure(options)
    value       = nil
    
    provisioner = config.get(:provisioner, nil)
    
    hiera_scope = config.get(:hiera_scope, {})
    override    = config.get(:override, nil)
    context     = config.get(:context, :priority)    
    
    
    return_property = config.get(:return_property, false)
    
    unless properties.is_a?(Array)
      properties = [ properties ].flatten
    end

    first_property = nil
    properties.each do |property|
      property       = property.to_sym
      first_property = property unless first_property
      
      # Try to load facts first (these can not be overridden)
      unless value = fact(property)<commit_msg>Adjusting the config initialized method in the lookup mixin.<commit_after>
module CORL
module Mixin
module Lookup

  #-----------------------------------------------------------------------------
  # Facter lookup
  
  def facts
    fact_map = {}
    Facter.list.each do |name|
      fact_map[name] = Facter.value(name)
    end
    fact_map
  end
  
  def fact(name)
    Facter.value(name)
  end
  
  #-----------------------------------------------------------------------------
  # Hiera configuration
  
  @@hiera = nil
  
  #---
  
  def hiera_config
    config_file = CORL.value(:hiera_config_file, nil)
    config      = {}

    if config_file && File.exist?(config_file)
      config = Hiera::Config.load(config_file)
    end
    config[:logger] = :corl
    
    results = CORL.config(:hiera_config, { :config => config })
    results[:config]
  end
  
  #---

  def hiera
    @@hiera = Hiera.new(:config => hiera_config) if @@hiera.nil?
    @@hiera
  end
  
  #-----------------------------------------------------------------------------
  # Configuration lookup interface
      
  def config_initialized?
    ready = false
    if CORL.admin? && hiera && network_path = fact(:corl_network)
      ready = File.directory?(File.join(network_path, 'config')) ? true : false
    end
    ready
  end
  
  #---
    
  def lookup(properties, default = nil, options = {})
    config      = Config.ensure(options)
    value       = nil
    
    provisioner = config.get(:provisioner, nil)
    
    hiera_scope = config.get(:hiera_scope, {})
    override    = config.get(:override, nil)
    context     = config.get(:context, :priority)    
    
    return_property = config.get(:return_property, false)
    
    unless properties.is_a?(Array)
      properties = [ properties ].flatten
    end

    first_property = nil
    properties.each do |property|
      property       = property.to_sym
      first_property = property unless first_property
      
      # Try to load facts first (these can not be overridden)
      unless value = fact(property)
{'fraction_non_alphanumeric': 0.20714111029591586, 'fraction_numerical': 0.0, 'mean_word_length': 1.673202614379085, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '205129', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1185, 'n_words': 268}