<commit_before>module Less
  class Interaction
    # Initialize the objects for an interaction. You should override this in your interactions. 
    # @param [Hash] options   The options are passed when running an interaction
    def initialize(options = {})
    end

    # Definition of the interaction itself. You should override this in your interactions
    #
    # The default implementation raises an {InvalidInteractionError}
    def run
      raise InvalidInteractionError, "You most override the run instance method in #{self.class}"
    end

    # Run your interaction.
    # @param [Hash] options   
    #
    # This will initialize your interaction with the options you pass to it and then call its {#run} method.
    def self.run(options = {})
      raise InvalidInteractionError, "Every interaction must be initialized with an options hash" unless options.is_a?(Hash)
      raise MissingParameterError unless expectations_met?(options)
      self.new(options).run
    end

    # Expect certain parameters to be present. If any parameter can't be found, a {MissingParameterError} will be raised. 
    # @overload expects(*parameters)
    #   @param *parameters A list of parameters that your interaction expects to find. 
    # @overload expects(*parameters, options)
    #   @param *parameters A list of parameters that your interaction expects to find. 
    #   @param options A list of options for the exclusion
    #   @option options :allow_nil Allow nil values to be passed to the interaction, only check to see whether the key has been set
 
    def self.expects(*parameters)
      if parameters.last.is_a?(Hash)
	options = parameters.pop
      else
	options = {}
      end
      parameters.each { |param| add_expectation(param, options) }
    end

    private

    def self.add_expectation(parameter, options)
      expectations[parameter] = options
    end

    def self.expectations_met?(options)
      expectations.each do |param, param_options|
	if param_options[:allow_nil]
	  raise MissingParameterError unless options.keys.member?(param)
	else
	  raise MissingParameterError unless options[param]
	end
      end
    end

    def self.expectations
      @expectations ||= {}
    end<commit_msg>more meaningful error messages when params are missing<commit_after>module Less
  class Interaction
    # Initialize the objects for an interaction. You should override this in your interactions. 
    # @param [Hash] options   The options are passed when running an interaction
    def initialize(options = {})
    end

    # Definition of the interaction itself. You should override this in your interactions
    #
    # The default implementation raises an {InvalidInteractionError}
    def run
      raise InvalidInteractionError, "You most override the run instance method in #{self.class}"
    end

    # Run your interaction.
    # @param [Hash] options   
    #
    # This will initialize your interaction with the options you pass to it and then call its {#run} method.
    def self.run(options = {})
      raise InvalidInteractionError, "Every interaction must be initialized with an options hash" unless options.is_a?(Hash)
      raise MissingParameterError unless expectations_met?(options)
      self.new(options).run
    end

    # Expect certain parameters to be present. If any parameter can't be found, a {MissingParameterError} will be raised. 
    # @overload expects(*parameters)
    #   @param *parameters A list of parameters that your interaction expects to find. 
    # @overload expects(*parameters, options)
    #   @param *parameters A list of parameters that your interaction expects to find. 
    #   @param options A list of options for the exclusion
    #   @option options :allow_nil Allow nil values to be passed to the interaction, only check to see whether the key has been set
 
    def self.expects(*parameters)
      if parameters.last.is_a?(Hash)
	options = parameters.pop
      else
	options = {}
      end
      parameters.each { |param| add_expectation(param, options) }
    end

    private

    def self.add_expectation(parameter, options)
      expectations[parameter] = options
    end

    def self.expectations_met?(options)
      expectations.each do |param, param_options|
	if param_options[:allow_nil]
	  raise MissingParameterError, "Parameter not passed   :#{param.to_s}" unless options.keys.member?(param)
	else
	  raise MissingParameterError, "Paramter empty   :#{param.to_s}" unless options[param]
	end
      end
    end

    def self.expectations
      @expectations ||= {}
    end
{'fraction_non_alphanumeric': 0.06758832565284179, 'fraction_numerical': 0.0, 'mean_word_length': 3.3203791469194313, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6629146', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1145, 'n_words': 473}