<commit_before>require 'yaml'

module Fastlane
  module Actions
    class RevertPatchAction < Action
      def self.run(params)
        if params[:patch]
          # raises
          patch = YAML.load_file params[:patch]

          # If the :patch option is present, load these params from the
          # specified file. Action args override.
          %w{regexp text mode global}.each do |option|
            value = patch[option]
            next if value.nil?

            case option.to_sym
            when :regexp
              params[:regexp] = /#{value}/
            when :mode
              params[:mode] = value.to_sym
            else
              params[option.to_sym] = value
            end
          end
        end

        UI.user_error! "Must specify :regexp and :text either in a patch or via arguments" if
          params[:regexp].nil? || params[:text].nil?

        helper = Fastlane::Helper::PatchHelper
        modified_contents = File.open(params[:file], "r") do |f|
          contents = f.read
          helper.revert_patch contents,
                             params[:regexp],
                             params[:text],
                             params[:global],
                             params[:mode],
                             params[:offset]
        end

        File.open(params[:file], "w") { |f| f.write modified_contents }
      rescue => e
        UI.user_error! "Error in RevertPatchAction: #{e.message}\n#{e.backtrace}"
      end

      def self.description
        "Apply and revert pattern-based patches to any text file."
      end

      def self.authors
        ["<NAME>"]
      end

      def self.return_value
        # If your method provides a return value, you can describe here what it does
      end<commit_msg>Dear RuboCop: Thanks for keeping me on the straight and narrow.<commit_after>require 'yaml'

module Fastlane
  module Actions
    class RevertPatchAction < Action
      def self.run(params)
        if params[:patch]
          # raises
          patch = YAML.load_file params[:patch]

          # If the :patch option is present, load these params from the
          # specified file. Action args override.
          %w{regexp text mode global}.each do |option|
            value = patch[option]
            next if value.nil?

            case option.to_sym
            when :regexp
              params[:regexp] = /#{value}/
            when :mode
              params[:mode] = value.to_sym
            else
              params[option.to_sym] = value
            end
          end
        end

        UI.user_error! "Must specify :regexp and :text either in a patch or via arguments" if
          params[:regexp].nil? || params[:text].nil?

        helper = Fastlane::Helper::PatchHelper
        modified_contents = File.open(params[:file], "r") do |f|
          contents = f.read
          helper.revert_patch contents,
                              params[:regexp],
                              params[:text],
                              params[:global],
                              params[:mode],
                              params[:offset]
        end

        File.open(params[:file], "w") { |f| f.write modified_contents }
      rescue => e
        UI.user_error! "Error in RevertPatchAction: #{e.message}\n#{e.backtrace}"
      end

      def self.description
        "Apply and revert pattern-based patches to any text file."
      end

      def self.authors
        ["<NAME>"]
      end

      def self.return_value
        # If your method provides a return value, you can describe here what it does
      end
{'fraction_non_alphanumeric': 0.08876560332871013, 'fraction_numerical': 0.0, 'mean_word_length': 1.5412262156448202, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1458964', 'n_tokens_mistral': 935, 'n_tokens_neox': 919, 'n_words': 287}