<commit_before>module Percheron
  module Actions
    class Create

      include Base

      def initialize(unit, start: false, cmd: false, exec_scripts: true)
        @unit = unit
        @start = start
        @exec_scripts = exec_scripts
        @cmd = cmd
        @unit_image_existed = unit.image_exists?
      end

      def execute!
        results = []
        if unit.exists?
          $logger.debug "Unit '#{unit.display_name}' already exists"
        else
          results << create!
        end
        results.compact.empty? ? nil : unit
      end

      private

        attr_reader :unit, :start, :exec_scripts, :unit_image_existed
        alias_method :start?, :start
        alias_method :exec_scripts?, :exec_scripts
        alias_method :unit_image_existed?, :unit_image_existed

        def cmd
          @cmd ||= (@cmd || unit.start_args)
        end

        def base_options
          {
            'name'          => unit.full_name,
            'Image'         => unit.image_name,
            'Hostname'      => unit.hostname,
            'Env'           => unit.env,
            'ExposedPorts'  => unit.exposed_ports,
            'Cmd'           => cmd,
            'Labels'        => unit.labels
          }
        end

        def host_config_options
          {
            'HostConfig'    => {
              'PortBindings'  => port_bindings,
              'Links'         => unit.links,
              'Binds'         => unit.volumes,
              'RestartPolicy' => unit.restart_policy,
              'Privileged'    => unit.privileged
            }
          }
        end

        def host_config_dns_options<commit_msg>Minor formatting fix<commit_after>module Percheron
  module Actions
    class Create

      include Base

      def initialize(unit, start: false, cmd: false, exec_scripts: true)
        @unit = unit
        @start = start
        @exec_scripts = exec_scripts
        @cmd = cmd
        @unit_image_existed = unit.image_exists?
      end

      def execute!
        results = []
        if unit.exists?
          $logger.debug "Unit '#{unit.display_name}' already exists"
        else
          results << create!
        end
        results.compact.empty? ? nil : unit
      end

      private

        attr_reader :unit, :start, :exec_scripts, :unit_image_existed
        alias_method :start?, :start
        alias_method :exec_scripts?, :exec_scripts
        alias_method :unit_image_existed?, :unit_image_existed

        def cmd
          @cmd ||= (@cmd || unit.start_args)
        end

        def base_options
          {
            'name'          => unit.full_name,
            'Image'         => unit.image_name,
            'Hostname'      => unit.hostname,
            'Env'           => unit.env,
            'ExposedPorts'  => unit.exposed_ports,
            'Cmd'           => cmd,
            'Labels'        => unit.labels
          }
        end

        def host_config_options
          {
            'HostConfig' => {
              'PortBindings'  => port_bindings,
              'Links'         => unit.links,
              'Binds'         => unit.volumes,
              'RestartPolicy' => unit.restart_policy,
              'Privileged'    => unit.privileged
            }
          }
        end

        def host_config_dns_options
{'fraction_non_alphanumeric': 0.09305135951661632, 'fraction_numerical': 0.0, 'mean_word_length': 1.413265306122449, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, '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': '3604964', 'n_tokens_mistral': 934, 'n_tokens_neox': 912, 'n_words': 199}