<commit_before>require 'yaml'
require 'hashr'
require 'socket'
require 'travis/worker/virtual_machine'

module Travis
  module Worker
    class Config < Hashr
      module Vms
        def count
         self[:count]
        end

        def name_prefix
          "travis-#{Travis::Worker.config.env}"
        end

        def names
          (1..count.to_i).map { |num| "#{name_prefix}-#{num}" }
        end

        def provision?
          !recipes.empty? && File.directory?(cookbooks)
        end
      end

      define :amqp      => { :username => 'guest', :password => '<PASSWORD>', :host => 'localhost' },
             :heartbeat => { :interval => 10 },
             :log_level => :info,
             :queue     => 'builds.common',
             :logging_channel => 'reporting.jobs.logs',
             :shell     => { :buffer => 0.5 },
             :timeouts  => { :hard_limit => 3000 },
             :vms       => { :provider => 'virtual_box', :count => 1, :_include => Vms },
             :limits    => { :log_length => 4, :last_flushed => 10 }

      def name
        @name ||= host.split('.').first
      end

      def names
        @names ||= VirtualMachine.provider.vm_names.map { |name| name.gsub(/^travis-/, '') }
      end
      
      def host
        @host ||= self[:host] || Socket.gethostname
      end

      def initialize
        super(read)
      end

      protected

        LOCATIONS = ['./config/', '~/.']

        def read
          local = read_yml(path)
          env   = local['env']
          local = local[env] || {}
          read_yml(path('base')).deep_merge(read_yml(path(env)).deep_merge(local.merge('env' => env)))
        end

        def read_yml(file_path)
          YAML.load_file(File.expand_path(file_path)) || {}
        end

        def config_filename(environment)
          ['worker', environment, 'yml'].compact.join('.')
        end

        def path(environment = nil)
          filename = config_filename(environment)
          paths    = LOCATIONS.map { |p| "#{p}#{filename}" }

          if existing_path = paths.detect { |p| File.exists?(p) }
            existing_path
          else
            raise "Could not find a configuration file. Valid paths are: #{paths.join(', ')}"
          end
        end
    end
  end
end
<commit_msg>add a default mapping hash to the config<commit_after>require 'yaml'
require 'hashr'
require 'socket'
require 'travis/worker/virtual_machine'

module Travis
  module Worker
    class Config < Hashr
      module Vms
        def count
         self[:count]
        end

        def name_prefix
          "travis-#{Travis::Worker.config.env}"
        end

        def names
          (1..count.to_i).map { |num| "#{name_prefix}-#{num}" }
        end

        def provision?
          !recipes.empty? && File.directory?(cookbooks)
        end
      end

      define :amqp      => { :username => 'guest', :password => '<PASSWORD>', :host => 'localhost' },
             :heartbeat => { :interval => 10 },
             :log_level => :info,
             :queue     => 'builds.common',
             :logging_channel => 'reporting.jobs.logs',
             :shell     => { :buffer => 0.5 },
             :timeouts  => { :hard_limit => 3000 },
             :vms       => { :provider => 'virtual_box', :count => 1, :_include => Vms },
             :limits    => { :log_length => 4, :last_flushed => 10 },
             :language_mappings => { }

      def name
        @name ||= host.split('.').first
      end

      def names
        @names ||= VirtualMachine.provider.vm_names.map { |name| name.gsub(/^travis-/, '') }
      end
      
      def host
        @host ||= self[:host] || Socket.gethostname
      end

      def initialize
        super(read)
      end

      protected

        LOCATIONS = ['./config/', '~/.']

        def read
          local = read_yml(path)
          env   = local['env']
          local = local[env] || {}
          read_yml(path('base')).deep_merge(read_yml(path(env)).deep_merge(local.merge('env' => env)))
        end

        def read_yml(file_path)
          YAML.load_file(File.expand_path(file_path)) || {}
        end

        def config_filename(environment)
          ['worker', environment, 'yml'].compact.join('.')
        end

        def path(environment = nil)
          filename = config_filename(environment)
          paths    = LOCATIONS.map { |p| "#{p}#{filename}" }

          if existing_path = paths.detect { |p| File.exists?(p) }
            existing_path
          else
            raise "Could not find a configuration file. Valid paths are: #{paths.join(', ')}"
          end
        end
    end
  end
end

{'fraction_non_alphanumeric': 0.1424574994620185, 'fraction_numerical': 0.005595007531740908, 'mean_word_length': 1.7389510901591043, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 48, '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': '1654381', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1379, 'n_words': 308}