<commit_before>require 'erubis'

module Config
  module Patterns
    class File < Config::Pattern

      desc "The full path of the file"
      key :path

      desc "The user that owns the file"
      attr :owner, nil

      desc "The group that owns the file"
      attr :group, nil

      desc "The octal mode of the file, such as 0755"
      attr :mode, nil

      desc "Set the mtime of the file to now"
      attr :touch, false

      desc "Specify the literal file content"
      attr :content, nil

      desc "Specify that content comes from a template file"
      attr :template_path, nil

      desc "Specify the object to provide the template binding"
      attr :template_context, nil

      desc "The operation to perform. See append! and only_create!"
      attr :operation, :write

      def describe
        "File #{pn}"
      end

      # Public: Appending is a questionable operation so call it with
      # bang for confidence.
      #
      # Returns nothing.
      def append!
        self.operation = :append
      end

      # Public: Not modifying an existing file is a questionable
      # operation so call it with bang for confidence.
      #
      # Returns nothing.
      def only_create!
        self.operation = :only_create
      end

      def validate
        if content.nil?
          if template_path.nil? || template_context.nil?
            validation_errors << "You must set either `content` or (`template_path` and `template_context`)"
          end
          if template_path && !::File.exist?(template_path)
            validation_errors << "template_path #{template_path} does not exist"
          end
          if template_context && !template_context.respond_to?(:get_binding)
            validation_errors << "template_context must define #get_binding"
          end
        end
      end

      class ColorizingEruby < Erubis::Eruby
        include Config::Core::Loggable

        def add_expr_literal(src, code)
          src << '_buf << (' << colorize(code) << ');'
        end

      protected

        # Formats a colored string [key:value]
        def colorize(code)
          if log.color?
            '"' + log.colorize("#{code.strip}:", :blue) + log.colorize("\#{#{code}}", :red) + '"'<commit_msg>colorize File logging to show where varaibles are used<commit_after>require 'erubis'

module Config
  module Patterns
    class File < Config::Pattern

      desc "The full path of the file"
      key :path

      desc "The user that owns the file"
      attr :owner, nil

      desc "The group that owns the file"
      attr :group, nil

      desc "The octal mode of the file, such as 0755"
      attr :mode, nil

      desc "Set the mtime of the file to now"
      attr :touch, false

      desc "Specify the literal file content"
      attr :content, nil

      desc "Specify that content comes from a template file"
      attr :template_path, nil

      desc "Specify the object to provide the template binding"
      attr :template_context, nil

      desc "The operation to perform. See append! and only_create!"
      attr :operation, :write

      def describe
        "File #{pn}"
      end

      # Public: Appending is a questionable operation so call it with
      # bang for confidence.
      #
      # Returns nothing.
      def append!
        self.operation = :append
      end

      # Public: Not modifying an existing file is a questionable
      # operation so call it with bang for confidence.
      #
      # Returns nothing.
      def only_create!
        self.operation = :only_create
      end

      def validate
        if content.nil?
          if template_path.nil? || template_context.nil?
            validation_errors << "You must set either `content` or (`template_path` and `template_context`)"
          end
          if template_path && !::File.exist?(template_path)
            validation_errors << "template_path #{template_path} does not exist"
          end
          if template_context && !template_context.respond_to?(:get_binding)
            validation_errors << "template_context must define #get_binding"
          end
        end
      end

      class ColorizingEruby < Erubis::Eruby
        include Config::Core::Loggable

        def add_expr_literal(src, code)
          src << '_buf << (' << colorize(code) << ');'
        end

      protected

        def colorize(code)
          if log.color?
            '"' + log.colorize("#{code.strip}:", :blue) + log.colorize("\#{#{code}}", :red) + '"'
{'fraction_non_alphanumeric': 0.08533333333333333, 'fraction_numerical': 0.0017777777777777779, 'mean_word_length': 2.1541695865451995, 'pattern_counts': {'":': 0, '<': 35, '<?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': '3597885', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1203, 'n_words': 447}