<commit_before>module Dapp
  module Builder
    class Base
      include CommonHelper
      include Centos7
      include Ubuntu1404
      include Ubuntu1604

      attr_reader :docker
      attr_reader :conf

      STAGES_DEPENDENCIES = {
          prepare: nil,
          infra_install: :prepare,
          sources_1: :infra_install,
          infra_setup: :sources_1,
          app_install: :infra_setup,
          sources_2: :app_install,
          app_setup: :sources_2,
          sources_3: :app_setup,
          sources_4: :sources_3
      }.freeze

      STAGES_DEPENDENCIES.each do |stage, dependence|
        define_method :"#{stage}_from" do
          send(:"#{dependence}_key") unless dependence.nil?
        end

        define_method :"#{stage}_image" do
          "dapp:#{send(:"#{stage}_key")}"
        end

        define_method :"#{stage}!" do
          build_stage!(from: send(:"#{stage}_from"), stage: stage)
        end

        define_method :"#{stage}?" do
          @docker.image_exist?(send("#{stage}_image"))
        end

        define_method stage do
          raise
        end
      end

      # TODO Describe stages sequence with
      # TODO   ordering data
      # TODO Generate stages related methods
      # TODO   from that data

      def initialize(docker, conf)
        @docker = docker
        @conf = conf
      end

      def run
        if prepare?
          prepare!
          infra_install!
          sources_1!
          infra_setup!
          app_install!
          app_setup!
        elsif infra_install?
          infra_install!
          sources_1!
          infra_setup!
          app_install!
          app_setup!
        elsif infra_setup?
          infra_setup!
          app_install!
          sources_2!
          app_setup!
        elsif app_install?
          app_install!
          sources_2!
          app_setup!
        elsif app_setup?
          app_setup!
          sources_3!
          sources_4!
        end
      end

      def build_stage!(from:, stage:)
        raise
      end


      def prepare
        method = :"from_#{conf[:from].split(/[:.]/).join}"
        send(method) if respond_to?(method)
      end

      def prepare_from
        conf[:from]
      end


      def infra_install_key
        infra_install_from
      end<commit_msg>modified Builder::Base#prepare<commit_after>module Dapp
  module Builder
    class Base
      include CommonHelper
      include Centos7
      include Ubuntu1404
      include Ubuntu1604

      attr_reader :docker
      attr_reader :conf

      STAGES_DEPENDENCIES = {
          prepare: nil,
          infra_install: :prepare,
          sources_1: :infra_install,
          infra_setup: :sources_1,
          app_install: :infra_setup,
          sources_2: :app_install,
          app_setup: :sources_2,
          sources_3: :app_setup,
          sources_4: :sources_3
      }.freeze

      STAGES_DEPENDENCIES.each do |stage, dependence|
        define_method :"#{stage}_from" do
          send(:"#{dependence}_key") unless dependence.nil?
        end

        define_method :"#{stage}_image" do
          "dapp:#{send(:"#{stage}_key")}"
        end

        define_method :"#{stage}!" do
          build_stage!(from: send(:"#{stage}_from"), stage: stage)
        end

        define_method :"#{stage}?" do
          @docker.image_exist?(send("#{stage}_image"))
        end

        define_method stage do
          raise
        end
      end

      # TODO Describe stages sequence with
      # TODO   ordering data
      # TODO Generate stages related methods
      # TODO   from that data

      def initialize(docker, conf)
        @docker = docker
        @conf = conf
      end

      def run
        if prepare?
          prepare!
          infra_install!
          sources_1!
          infra_setup!
          app_install!
          app_setup!
        elsif infra_install?
          infra_install!
          sources_1!
          infra_setup!
          app_install!
          app_setup!
        elsif infra_setup?
          infra_setup!
          app_install!
          sources_2!
          app_setup!
        elsif app_install?
          app_install!
          sources_2!
          app_setup!
        elsif app_setup?
          app_setup!
          sources_3!
          sources_4!
        end
      end

      def build_stage!(from:, stage:)
        raise
      end


      def prepare
        prepare_options
      end

      def prepare_key
        sha256([prepare_from, prepare_options])
      end

      def prepare_from
        conf[:from]
      end

      def prepare_options
        @prepare_options ||= begin
          method = :"from_#{conf[:from].split(/[:.]/).join}"
          raise "unsupported docker image '#{conf[:from]}'" unless respond_to?(method)
          resp = send(method)
          docker_opts = resp.last.is_a? Hash ? resp.pop : {}
          docker_opts[:expose] = conf[:exposes]
          resp.push(docker_opts)
        end
      end


      def infra_install_key
        infra_install_from
      end
{'fraction_non_alphanumeric': 0.08166501486620416, 'fraction_numerical': 0.009316154608523291, 'mean_word_length': 1.6363636363636365, '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': '5797538', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1429, 'n_words': 333}