<commit_before>require 'erb'

module Dockerb
  class << self
    def compile
      return (yield if block_given?) unless File.exist?("Dockerfile.erb")
      begin
        File.write("Dockerfile", Context.compile(File.read("Dockerfile.erb")))
        yield if block_given?
      ensure
        File.unlink("Dockerfile") if File.exist?("Dockerfile") && block_given?
      end
    end
  end

  class Context
    class << self
      def compile(code)
        warn = "# Generated by dockerb, do not modify\n"
        warn + ERB.new(code).result(binding).strip + "\n" + warn
      end

      def bundle
        <<-EOF.gsub(/^          /, "")
          ADD Gemfile /app/
          ADD Gemfile.lock /app/
          ADD vendor/cache /app/vendor/cache
          RUN (bundle install --quiet --local --jobs 4 || bundle check) && #{delete_gem_junk}
        EOF
      end

      def install_gem(name, options=nil)
        options = " " << options if options
        version = File.read("Gemfile.lock")[/^    #{name} \((.+)\)/, 1] || raise("Gem #{name} not found in Gemfile.lock")
        "RUN gem install -v #{version} #{name}#{options} && #{delete_gem_junk}"
      end

      def delete_gem_junk
        "#{delete_tests} && #{delete_build_files}"
      end

      private

      def delete_tests
        %{find #{gem_home}/ -maxdepth 2 -name "test" -o -name "spec" | xargs rm -r}
      end

      # deleting all of ext makes nokogiri + Nokogumbo install fail
      def delete_build_files
        %{find #{gem_home}/*/ext/ -maxdepth 1 -mindepth 1 -type d | xargs -L1 bash -c 'if [ -e $0/Makefile ]; then make -C $0 clean; fi}
      end

      def gem_home
        "/usr/local/lib/ruby/gems/*/gems"
      end
    end
  end
end
<commit_msg>closing quote<commit_after>require 'erb'

module Dockerb
  class << self
    def compile
      return (yield if block_given?) unless File.exist?("Dockerfile.erb")
      begin
        File.write("Dockerfile", Context.compile(File.read("Dockerfile.erb")))
        yield if block_given?
      ensure
        File.unlink("Dockerfile") if File.exist?("Dockerfile") && block_given?
      end
    end
  end

  class Context
    class << self
      def compile(code)
        warn = "# Generated by dockerb, do not modify\n"
        warn + ERB.new(code).result(binding).strip + "\n" + warn
      end

      def bundle
        <<-EOF.gsub(/^          /, "")
          ADD Gemfile /app/
          ADD Gemfile.lock /app/
          ADD vendor/cache /app/vendor/cache
          RUN (bundle install --quiet --local --jobs 4 || bundle check) && #{delete_gem_junk}
        EOF
      end

      def install_gem(name, options=nil)
        options = " " << options if options
        version = File.read("Gemfile.lock")[/^    #{name} \((.+)\)/, 1] || raise("Gem #{name} not found in Gemfile.lock")
        "RUN gem install -v #{version} #{name}#{options} && #{delete_gem_junk}"
      end

      def delete_gem_junk
        "#{delete_tests} && #{delete_build_files}"
      end

      private

      def delete_tests
        %{find #{gem_home}/ -maxdepth 2 -name "test" -o -name "spec" | xargs rm -r}
      end

      # deleting all of ext makes nokogiri + Nokogumbo install fail
      def delete_build_files
        %{find #{gem_home}/*/ext/ -maxdepth 1 -mindepth 1 -type d | xargs -L1 bash -c 'if [ -e $0/Makefile ]; then make -C $0 clean; fi'}
      end

      def gem_home
        "/usr/local/lib/ruby/gems/*/gems"
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.1342418092200638, 'fraction_numerical': 0.004639025804581038, 'mean_word_length': 2.047703180212014, 'pattern_counts': {'":': 0, '<': 19, '<?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': '1402797', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1107, 'n_words': 313}