<commit_before>$LOAD_PATH.unshift(File.dirname(__FILE__))

require 'xpf/configuration'
require 'xpf/arguments_parsing'
require 'xpf/path_building'

module XPF

  class ModeAlreadyDeclaredError < Exception ; end
  class InvalidConfigModeError   < Exception ; end

  class << self

    include PathBuilding
    include ArgumentsParsing

    ###
    # Do configuration, which can be:
    #
    # 1). Customize global configuration (see Configuration for all configurable settings):
    #
    #   XPF.configure do |config|
    #     # This will turn off case senstive matching, all xpath generated will
    #     # ignore chars casing
    #     config.case_sensitive = false
    #   end
    #
    # 2). Reset configuration to default:
    #
    #   XPF.configure(:reset)
    #
    def configure(mode = :update, &blk)
      case mode
      when :update then yield(Configuration)
      when :reset then Configuration.reset
      else raise InvalidConfigModeError.new("Config mode :#{mode} is not supported !!")
      end
    end

    ###
    # Befriending simply means introducing the easier to type +someone.xpf+. If +someone+
    # already has that method, a warning will be issued & no addition is done.
    #
    # Currently, the only use case is to add xpf() to Object, thus usage becomes:
    #
    #   xpf.tr(...)
    #
    # Which has exactly the same effect as:
    #
    #   XPF.tr(...)
    #
    def befriends(someone)
      unless (@friends ||= []).include?(someone)
        if someone.method_defined?(:xpf)
          $stdout.puts %w{
            WARNING: XPF wants to befriend %s by giving it a shortcut method xpf(), but
            %s#xpf has already been defined. Neverthless, the rejected XPF stays friendly
            & XPF's goodies can still be accessed via the less easy to type XPF.*.
          }.join(' ') % ([someone]*2)
        else
          @friends << someone
          someone.send(:define_method, :xpf, lambda { XPF })
        end
      end
    end

    protected

      ###
      # This is to avoid XPF from running in multiple modes. Once mode has been declared
      # redeclaring will raise XPF::ModeAlreadyDeclaredError.
      #
      def declare_mode_as(mode)
        if const_defined?(:MODE)
          raise ModeAlreadyDeclaredError.new("Mode has already been declared as :#{MODE} !!")
        else
          const_set(:MODE, mode)
        end
      end

  end

  # NOTE: This is not tested !!
  XPF.befriends(Object)

end

<commit_msg>We don wanna display doc for #declare_mode_as.<commit_after>$LOAD_PATH.unshift(File.dirname(__FILE__))

require 'xpf/configuration'
require 'xpf/arguments_parsing'
require 'xpf/path_building'

module XPF

  class ModeAlreadyDeclaredError < Exception ; end
  class InvalidConfigModeError   < Exception ; end

  class << self

    include PathBuilding
    include ArgumentsParsing

    ###
    # Do configuration, which can be:
    #
    # 1). Customize global configuration (see Configuration for all configurable settings):
    #
    #   XPF.configure do |config|
    #     # This will turn off case senstive matching, all xpath generated will
    #     # ignore chars casing
    #     config.case_sensitive = false
    #   end
    #
    # 2). Reset configuration to default:
    #
    #   XPF.configure(:reset)
    #
    def configure(mode = :update, &blk)
      case mode
      when :update then yield(Configuration)
      when :reset then Configuration.reset
      else raise InvalidConfigModeError.new("Config mode :#{mode} is not supported !!")
      end
    end

    ###
    # Befriending simply means introducing the easier to type +someone.xpf+. If +someone+
    # already has that method, a warning will be issued & no addition is done.
    #
    # Currently, the only use case is to add xpf() to Object, thus usage becomes:
    #
    #   xpf.tr(...)
    #
    # Which has exactly the same effect as:
    #
    #   XPF.tr(...)
    #
    def befriends(someone)
      unless (@friends ||= []).include?(someone)
        if someone.method_defined?(:xpf)
          $stdout.puts %w{
            WARNING: XPF wants to befriend %s by giving it a shortcut method xpf(), but
            %s#xpf has already been defined. Neverthless, the rejected XPF stays friendly
            & XPF's goodies can still be accessed via the less easy to type XPF.*.
          }.join(' ') % ([someone]*2)
        else
          @friends << someone
          someone.send(:define_method, :xpf, lambda { XPF })
        end
      end
    end

    protected

      ###
      # This is to avoid XPF from running in multiple modes. Once mode has been declared
      # redeclaring will raise XPF::ModeAlreadyDeclaredError.
      #
      def declare_mode_as(mode) #:nodoc:
        if const_defined?(:MODE)
          raise ModeAlreadyDeclaredError.new("Mode has already been declared as :#{MODE} !!")
        else
          const_set(:MODE, mode)
        end
      end

  end

  # NOTE: This is not tested !!
  XPF.befriends(Object)

end


{'fraction_non_alphanumeric': 0.09180393732422659, 'fraction_numerical': 0.0012053033346725592, 'mean_word_length': 2.375593220338983, 'pattern_counts': {'":': 0, '<': 15, '<?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': '7001078', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1417, 'n_words': 486}