<commit_before>module Percheron
  module Container
    class Main

      extend Forwardable
      extend ConfigDelegator

      def_delegators :container_config, :name, :dockerfile_md5

      def_config_item_with_default :container_config, false, :auto_recreate
      def_config_item_with_default :container_config, [], :env, :ports, :volumes, :dependant_container_names

      alias_method :auto_recreate?, :auto_recreate

      def initialize(config, stack, container_name)
        @config = config
        @stack = stack
        @container_name = container_name
        valid?
        self
      end

      def stop!
        Container::Actions::Stop.new(self).execute!
      rescue Errors::ContainerNotRunning
        $logger.debug "Container '#{name}' is not running"
      end

      def start!
        Container::Actions::Create.new(self).execute! unless exists?
        Container::Actions::Start.new(self).execute!
      end

      def id
        exists? ? info.id[0...12] : 'N/A'
      end

      def image
        '%s:%s' % [ name, version.to_s ]
      end

      def version
        Semantic::Version.new(container_config.version)
      end

      def built_version
        exists? ? Semantic::Version.new(info.Config.Image.split(':')[1]) : nil
      end

      def dockerfile
        container_config.dockerfile ? Pathname.new(File.expand_path(container_config.dockerfile, config.file_base_path)): nil
      end

      def exposed_ports
        ports.inject({}) do |all, p|
          all[p.split(':')[1]] = {}
          all
        end
      end

      def links
        dependant_container_names.map do |container_name|
          '%s:%s' % [ container_name, container_name ]
        end
      end

      def docker_container
        Docker::Container.get(name)
      rescue Docker::Error::NotFoundError, Excon::Errors::SocketError
        Container::Null.new
      end
<commit_msg>Moved Container::Main#stop!/start! around a bit<commit_after>module Percheron
  module Container
    class Main

      extend Forwardable
      extend ConfigDelegator

      def_delegators :container_config, :name, :dockerfile_md5

      def_config_item_with_default :container_config, false, :auto_recreate
      def_config_item_with_default :container_config, [], :env, :ports, :volumes, :dependant_container_names

      alias_method :auto_recreate?, :auto_recreate

      def initialize(config, stack, container_name)
        @config = config
        @stack = stack
        @container_name = container_name
        valid?
        self
      end

      def id
        exists? ? info.id[0...12] : 'N/A'
      end

      def image
        '%s:%s' % [ name, version.to_s ]
      end

      def version
        Semantic::Version.new(container_config.version)
      end

      def built_version
        exists? ? Semantic::Version.new(info.Config.Image.split(':')[1]) : nil
      end

      def dockerfile
        container_config.dockerfile ? Pathname.new(File.expand_path(container_config.dockerfile, config.file_base_path)): nil
      end

      def exposed_ports
        ports.inject({}) do |all, p|
          all[p.split(':')[1]] = {}
          all
        end
      end

      def links
        dependant_container_names.map do |container_name|
          '%s:%s' % [ container_name, container_name ]
        end
      end

      def docker_container
        Docker::Container.get(name)
      rescue Docker::Error::NotFoundError, Excon::Errors::SocketError
        Container::Null.new
      end

      def stop!
        Container::Actions::Stop.new(self).execute!
      rescue Errors::ContainerNotRunning
        $logger.debug "Container '#{name}' is not running"
      end

      def start!
        Container::Actions::Create.new(self).execute! unless exists?
        Container::Actions::Start.new(self).execute!
      end

{'fraction_non_alphanumeric': 0.1, 'fraction_numerical': 0.0031413612565445027, 'mean_word_length': 2.4361510791366907, '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': '222086', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1102, 'n_words': 236}