<commit_before>require 'cheffish/with_pattern'
require 'chef/mixin/deep_merge'

module ChefMetal
  class ChefRunData
    extend Cheffish::WithPattern
    def initialize(config)
      @config = config
      @drivers = {}
    end

    attr_reader :config
    attr_reader :drivers

    with :driver
    with :machine_options
    with :machine_batch

    def current_driver
      @current_driver || config[:driver]
    end

    def current_machine_options
      if @current_machine_options
        @current_machine_options
      elsif config[:drivers] && driver_for(current_driver) && config[:drivers][driver_for(current_driver).driver_url]
        MergedConfig.new(config[:drivers][driver_for(current_driver).driver_url], config)[:machine_options] || {}
      else
        config[:machine_options] || {}
      end
    end

    def add_machine_options(options, &block)
      with_machine_options(Chef::Mixin::DeepMerge.hash_only_merge(current_machine_options, options), &block)
    end

    def driver_for(driver)
      driver.is_a?(String) ? driver_for_url(driver) : driver
    end

    def driver_for_url(driver_url)
      drivers[driver_url] ||= begin
        driver = ChefMetal.driver_for_url(driver_url, config)<commit_msg>Get merged driver config working<commit_after>require 'cheffish/with_pattern'
require 'chef/mixin/deep_merge'
require 'cheffish/merged_config'

module ChefMetal
  class ChefRunData
    extend Cheffish::WithPattern
    def initialize(config)
      @config = config
      @drivers = {}
    end

    attr_reader :config
    attr_reader :drivers

    with :driver
    with :machine_options
    with :machine_batch

    def current_driver
      @current_driver || config[:driver]
    end

    def current_machine_options
      if @current_machine_options
        @current_machine_options
      elsif config[:drivers] && driver_for(current_driver) && config[:drivers][driver_for(current_driver).driver_url]
        Cheffish::MergedConfig.new(config[:drivers][driver_for(current_driver).driver_url], config)[:machine_options] || {}
      else
        config[:machine_options] || {}
      end
    end

    def add_machine_options(options, &block)
      with_machine_options(Chef::Mixin::DeepMerge.hash_only_merge(current_machine_options, options), &block)
    end

    def driver_for(driver)
      driver.is_a?(String) ? driver_for_url(driver) : driver
    end

    def driver_for_url(driver_url)
      drivers[driver_url] ||= begin
        driver = ChefMetal.driver_for_url(driver_url, config)
{'fraction_non_alphanumeric': 0.09282868525896415, 'fraction_numerical': 0.0, 'mean_word_length': 3.7919847328244276, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6516523', 'n_tokens_mistral': 793, 'n_tokens_neox': 766, 'n_words': 137}