<commit_before># frozen_string_literal: true

require_relative './manager.rb'
require_relative '../config.rb'

module Fusuma
  module Plugin
    # Create a Plugin Class with extending this class
    class Base
      # when inherited from subclass
      def self.inherited(subclass)
        subclass_path = caller_locations(1..1).first.path
        Manager.add(plugin_class: subclass, plugin_path: subclass_path)
      end

      # get inherited classes
      # @example
      #  [Vectors::Vector]
      # @return [Array]
      def self.plugins
        Manager.plugins[name]
      end

      # config parameter name and Type of the value of parameter
      # @return [Hash]
      def config_param_types
        raise NotImplementedError, "override #{self.class.name}##{__method__}"
      end

      # @return [Plugin::Base]
      def config_params(key = nil)
        params = Config.search(config_index) || {}

        return params unless key

        params.fetch(key, nil).tap do |val|
          next if val.nil?

          param_types = Array(config_param_types.fetch(key))

          next if param_types.any? { |klass| val.is_a?(klass) }

          MultiLogger.error('Please fix config.yml.')
          MultiLogger.error(":#{config_index.keys.map(&:symbol)
            .join(' => :')} => :#{key} should be #{param_types.join(' OR ')}.")
          exit 1
        end
      end

      def config_index
        Config::Index.new(self.class.name.gsub('Fusuma::', '').underscore.split('/'))
      end
    end
  end
end<commit_msg>Add a keyword argument to `Plugin::Base#config_params`<commit_after># frozen_string_literal: true

require_relative './manager.rb'
require_relative '../config.rb'

module Fusuma
  module Plugin
    # Create a Plugin Class with extending this class
    class Base
      # when inherited from subclass
      def self.inherited(subclass)
        subclass_path = caller_locations(1..1).first.path
        Manager.add(plugin_class: subclass, plugin_path: subclass_path)
      end

      # get inherited classes
      # @example
      #  [Vectors::Vector]
      # @return [Array]
      def self.plugins
        Manager.plugins[name]
      end

      # config parameter name and Type of the value of parameter
      # @return [Hash]
      def config_param_types
        raise NotImplementedError, "override #{self.class.name}##{__method__}"
      end

      # @return [Object]
      def config_params(key = nil, base: config_index)
        params = Config.search(base) || {}

        return params unless key

        params.fetch(key, nil).tap do |val|
          next if val.nil?

          # NOTE: Type checking for config.yml
          param_types = Array(config_param_types.fetch(key))

          next if param_types.any? { |klass| val.is_a?(klass) }

          MultiLogger.error('Please fix config.yml.')
          MultiLogger.error(":#{base.keys.map(&:symbol)
            .join(' => :')} => :#{key} should be #{param_types.join(' OR ')}.")
          exit 1
        end
      end

      def config_index
        Config::Index.new(self.class.name.gsub('Fusuma::', '').underscore.split('/'))
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11577608142493638, 'fraction_numerical': 0.0019083969465648854, 'mean_word_length': 2.3926645091693635, 'pattern_counts': {'":': 2, '<': 3, '<?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': '3711396', 'n_tokens_mistral': 952, 'n_tokens_neox': 922, 'n_words': 233}