<commit_before>require 'rack/utils'

module Acfs

  # Global handler for stubbing resources.
  #
  class Stub
    ACTIONS = [:read, :create, :update, :delete, :list]

    attr_reader :opts

    def initialize(opts)
      @opts = opts

      @opts[:with].stringify_keys! if @opts[:with].is_a? Hash
      @opts[:return].stringify_keys! if @opts[:return].is_a? Hash
      @opts[:return].map! { |h| h.stringify_keys! if h.is_a? Hash } if @opts[:return].is_a? Array
    end

    def accept?(op)
      return opts[:with].call op if opts[:with].respond_to? :call

      params = op.full_params.stringify_keys
      data   = op.data.stringify_keys

      return true if opts[:with] == params || data == opts[:with]
      return true if (opts[:with].nil? && params.empty? && data.empty?)

      return true if opts[:with].reject { |k, v| v.nil? } == params.reject { |k, v| v.nil? }
      return true if opts[:with].reject { |k, v| v.nil? } == data.reject { |k, v| v.nil? }

      false
    end

    def calls
      @calls ||= []
    end

    def called?(count = nil)
      count = count.count if count.respond_to? :count # For `5.times` Enumerators
      count.nil? ? calls.any? : calls.size == count
    end

    def call(op)
      calls << op
<commit_msg>Set with: to empty hash by default<commit_after>require 'rack/utils'

module Acfs

  # Global handler for stubbing resources.
  #
  class Stub
    ACTIONS = [:read, :create, :update, :delete, :list]

    attr_reader :opts

    def initialize(opts)
      @opts = opts

      @opts[:with].stringify_keys! if @opts[:with].is_a? Hash
      @opts[:return].stringify_keys! if @opts[:return].is_a? Hash
      @opts[:return].map! { |h| h.stringify_keys! if h.is_a? Hash } if @opts[:return].is_a? Array
    end

    def accept?(op)
      return opts[:with].call op if opts[:with].respond_to? :call

      params = op.full_params.stringify_keys
      data   = op.data.stringify_keys

      return true if opts[:with] == params || data == opts[:with]
      return true if opts[:with].nil? && params.empty? && data.empty?

      opts[:with] ||= {}
      return true if opts[:with].reject{|_, v| v.nil? } == params.reject {|_, v| v.nil? }
      return true if opts[:with].reject{|_, v| v.nil? } == data.reject {|_, v| v.nil? }

      false
    end

    def calls
      @calls ||= []
    end

    def called?(count = nil)
      count = count.count if count.respond_to? :count # For `5.times` Enumerators
      count.nil? ? calls.any? : calls.size == count
    end

    def call(op)
      calls << op

{'fraction_non_alphanumeric': 0.15272296764009471, 'fraction_numerical': 0.0007892659826361484, 'mean_word_length': 2.6739130434782608, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6369425', 'n_tokens_mistral': 870, 'n_tokens_neox': 849, 'n_words': 231}