<commit_before>require 'shellwords'

module Travis
  module Build
    class Script
      module Addons
        class Hosts
          SUPER_USER_SAFE = true

          attr_reader :sh, :config

          def initialize(sh, config)
            @sh = sh
            @config = [config].flatten
          end

          def after_pre_setup
            sh.fold 'hosts' do
              sh.raw "sudo sed -e 's/^\\(127\\.0\\.0\\.1.*\\)$/\\1 '#{config.join(' ').shellescape}'/' -i'.bak' /etc/hosts"
              sh.raw "sudo sed -e 's/^\\(::1.*\\)$/\\1 '#{config.join(' ').shellescape}'/' -i'.bak' /etc/hosts"
            end
          end
        end
      end
    end
  end
end<commit_msg>refactor Addons::Hosts<commit_after>require 'shellwords'
require 'travis/build/script/addons/base'

module Travis
  module Build
    class Script
      module Addons
        class Hosts < Base
          SUPER_USER_SAFE = true

          def after_pre_setup
            sh.fold 'hosts' do
              sh.cmd "sed -e 's/^\\(127\\.0\\.0\\.1.*\\)$/\\1 '#{hosts}'/' -i'.bak' /etc/hosts", sudo: true
              sh.cmd "sed -e 's/^\\(::1.*\\)$/\\1 '#{hosts}'/' -i'.bak' /etc/hosts", sudo: true
            end
          end

          private

            def hosts
              Array(config).join(' ').shellescape
            end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.15828402366863906, 'fraction_numerical': 0.013313609467455622, 'mean_word_length': 1.407473309608541, 'pattern_counts': {'":': 0, '<': 4, '<?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': '2351821', 'n_tokens_mistral': 470, 'n_tokens_neox': 440, 'n_words': 108}