<commit_before># -*- coding: utf-8 -*-
module EventMachine
  class FilesystemCommand < EM::SystemCommand

    PROGRESS_REGEXP = /([A-Za-z0-9\.\-]+)\n[ ]+(\d+)/.freeze

    class << self

      ##
      # Invokes an `rsync` copy-like command.
      def copy *args, &block
        options = { }.merge args.extract_options!
        cmd = FilesystemCommand.new 'rsync', '--progress', *args
        cmd.execute &block
      end

      ##
      # Invokes an `rsync` move-like command.
      def move
        options = { }.merge args.extract_options!
        cmd = FilesystemCommand.new 'rsync'
        cmd << '--progress'
        cmd << '--remove-source-files'
        cmd << '--force'
        cmd << args
        cmd.execute &block
      end

    end

    ##
    # Invokes `#execute` of super-class and adds a progress matcher.
    def execute &block
      super &block

      stdout.match PROGRESS_REGEXP, match: :last, in: :output do |file, bytes|
        receive_progress file, bytes.to_i
      end
    end

    ##
    # Is called when ever a `EM::FilesystemCommand` stdout updates the line
    # is matched the `EM::FilesystemCommand::PROGRESS_REGEXP`.
    #
    # Calls all defined callbacks for progress events.
    #
    # @param [String] file The file that´s been updated.
    # @param [Integer] bytes The bytes moved or copied.
    def receive_progress file, bytes
      progress_callbacks.each do |cb|
        cb.call file, bytes
      end
    end

    ##
    # Defines a progress callback.
    #
    # @yield The block to be stored as callback for progress events.
    # @yieldparam [String] file The file that´s been updated.
    # @yieldparam [Integer] bytes The bytes moved or copied.
    def progress &block<commit_msg>`EM::FilesystemCommand#execute` has to return itself for easy chaining<commit_after># -*- coding: utf-8 -*-
module EventMachine
  class FilesystemCommand < EM::SystemCommand

    PROGRESS_REGEXP = /([A-Za-z0-9\.\-]+)\n[ ]+(\d+)/.freeze

    class << self

      ##
      # Invokes an `rsync` copy-like command.
      def copy *args, &block
        options = { }.merge args.extract_options!
        cmd = FilesystemCommand.new 'rsync', '--progress', *args
        cmd.execute &block
      end

      ##
      # Invokes an `rsync` move-like command.
      def move
        options = { }.merge args.extract_options!
        cmd = FilesystemCommand.new 'rsync'
        cmd << '--progress'
        cmd << '--remove-source-files'
        cmd << '--force'
        cmd << args
        cmd.execute &block
      end

    end

    ##
    # Invokes `#execute` of super-class and adds a progress matcher.
    def execute &block
      super &block

      stdout.match PROGRESS_REGEXP, match: :last, in: :output do |file, bytes|
        receive_progress file, bytes.to_i
      end

      self
    end

    ##
    # Is called when ever a `EM::FilesystemCommand` stdout updates the line
    # is matched the `EM::FilesystemCommand::PROGRESS_REGEXP`.
    #
    # Calls all defined callbacks for progress events.
    #
    # @param [String] file The file that´s been updated.
    # @param [Integer] bytes The bytes moved or copied.
    def receive_progress file, bytes
      progress_callbacks.each do |cb|
        cb.call file, bytes
      end
    end

    ##
    # Defines a progress callback.
    #
    # @yield The block to be stored as callback for progress events.
    # @yieldparam [String] file The file that´s been updated.
    # @yieldparam [Integer] bytes The bytes moved or copied.
    def progress &block
{'fraction_non_alphanumeric': 0.10859087042812589, 'fraction_numerical': 0.001701162461015027, 'mean_word_length': 2.236697247706422, 'pattern_counts': {'":': 0, '<': 25, '<?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': '6415095', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1048, 'n_words': 345}