<commit_before># encoding: utf-8
module Imp

  class Manager

    include ::Imp::Signals

    class << self

      def register(process)

        raise ::Imp::Exception, "Process with name `#{process.name}` already registered!" unless self[process.name].nil?
        store[process.name] = process
        process

      end # register

      def [](name)
        store[name]
      end # get

      def each(&block)
        store.each_value(&block)
      end # each

      def names(&block)

        if block_given?
          store.each_key(&block)
        else
          store.keys
        end

      end # names

      private

      def store
        @hash ||= {}
      end # store

    end # class << self

    def initialize(name)

      @process = ::Imp::Manager[name]
      raise ::Imp::Exception, "Process with name `#{name}` not found!" if @process.nil?

    end # new

    def start

      @process.start
      nil

    end # start

    def stop(sig_name = 'QUIT')

      self.refresh
      walk do |pid|
        pid.stop(sig_name)
      end
      nil

    end # stop

    def restart

      self.stop
      sleep 0.2
      self.start

    end # restart

    def refresh
      @pids = nil
    end # refresh

    alias :reload :refresh

    def count
      pids.length
    end # count

    alias :size   :count
    alias :length :count

    def signal(name)

      walk do |pid|
        pid.signal(name)
      end
      nil

    end # signal

    def running?

      self.refresh
      self.count > 0

    end # running?

    alias :run?    :running?
    alias :exists? :running?
    alias :exist?  :running?

    def [](i)
      pids[i]
    end # []

    def inspect

      logs   = @process.instance_variable_get(:@log_file)
      block  = @process.instance_variable_get(:@block)
      pids_a = pids.map(&:pid)

      "#<Imp::Manager\n" <<
      " process:  #{@process.name},\n" <<
      " pids:     #{pids_a},\n" <<
      " running:  #{pids_a.length > 0},\n" <<
      " logs:     #{logs || '/dev/null'},\n" <<
      " block:    #{block}>\n"

    end # inspect

    alias :to_s   :inspect
    alias :to_str :inspect

    private

    def pids

      return @pids if @pids

      @pids = []
      ::Imp::Util::find_by_name(@process.name).each do |pid|
        @pids << ::Imp::Pid.new(pid)
      end
      @pids

    end # pids

    def walk

      pids.each do |pid|
        yield(pid)
      end

    end # walk

  end # Manager
<commit_msg>Если процесс не найден по заданному имени то, вместо исключения выводится сообщение об ошибке.<commit_after># encoding: utf-8
module Imp

  class Manager

    include ::Imp::Signals

    class << self

      def register(process)

        raise ::Imp::Exception, "Process with name `#{process.name}` already registered!" unless self[process.name].nil?
        store[process.name] = process
        process

      end # register

      def [](name)
        store[name]
      end # get

      def each(&block)
        store.each_value(&block)
      end # each

      def names(&block)

        if block_given?
          store.each_key(&block)
        else
          store.keys
        end

      end # names

      private

      def store
        @hash ||= {}
      end # store

    end # class << self

    def initialize(name)

      @process = ::Imp::Manager[name]
      puts "Error. Process with name `#{name}` not found!" if @process.nil?

    end # new

    def start

      @process.start if @process
      nil

    end # start

    def stop(sig_name = 'QUIT')

      self.refresh
      walk do |pid|
        pid.stop(sig_name)
      end
      nil

    end # stop

    def restart

      self.stop
      sleep 0.2
      self.start

    end # restart

    def refresh

      @pids = nil
      self

    end # refresh

    alias :reload :refresh

    def count
      pids.length
    end # count

    alias :size   :count
    alias :length :count

    def signal(name)

      walk do |pid|
        pid.signal(name)
      end
      nil

    end # signal

    def running?

      self.refresh
      self.count > 0

    end # running?

    alias :run?    :running?
    alias :exists? :running?
    alias :exist?  :running?

    def [](i)
      pids[i]
    end # []

    def inspect

      return unless @process

      logs   = @process.instance_variable_get(:@log_file)
      block  = @process.instance_variable_get(:@block)
      pids_a = pids.map(&:pid)

      "#<Imp::Manager\n" <<
      " process:  #{@process.name},\n" <<
      " pids:     #{pids_a},\n" <<
      " running:  #{pids_a.length > 0},\n" <<
      " logs:     #{logs || '/dev/null'},\n" <<
      " block:    #{block}>\n"

    end # inspect

    alias :to_s   :inspect
    alias :to_str :inspect

    private

    def pids

      return @pids  if @pids
      return []     unless @process

      @pids = []
      ::Imp::Util::find_by_name(@process.name).each do |pid|
        @pids << ::Imp::Pid.new(pid)
      end
      @pids

    end # pids

    def walk

      pids.each do |pid|
        yield(pid)
      end

    end # walk

  end # Manager

{'fraction_non_alphanumeric': 0.11717051966014622, 'fraction_numerical': 0.0019758940920766646, 'mean_word_length': 1.6954206602768902, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 9, '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': '4395740', 'n_tokens_mistral': 1712, 'n_tokens_neox': 1628, 'n_words': 434}