<commit_before>require 'apivore/rspec_matchers'
require 'action_controller'
require 'action_dispatch'
require 'rspec/mocks'
require 'hashie'

module Apivore
  module RspecBuilder
    include Apivore::RspecMatchers
    include ActionDispatch::Integration
    include RSpec::Mocks::ExampleMethods

    @@setups ||= {}

    @@master_swagger_uri = nil

    def apivore_setup(path, method, response, &block)
      @@setups[path + method + response] = block
    end

    def get_apivore_setup(path, method, response)
      setup = @@setups[path + method + response]
      if setup
        result = instance_eval &setup
      end
      (result && result.is_a?(Hash)) ? result : {}
    end

    def apivore_build_path(path, data)<commit_msg>allow apivore_setup blocks to be defined more generally<commit_after>require 'apivore/rspec_matchers'
require 'action_controller'
require 'action_dispatch'
require 'rspec/mocks'
require 'hashie'

module Apivore
  module RspecBuilder
    include Apivore::RspecMatchers
    include ActionDispatch::Integration
    include RSpec::Mocks::ExampleMethods

    @@setups ||= {}

    @@master_swagger_uri = nil

    def apivore_setup(path = '', method = '', response = '', &block)
      @@setups[path + method + response] = block
    end

    def get_apivore_setup(path, method, response)
      keys_to_search = [
        '', # base setup key
        response,
        method,
        path,
        method + response,
        # Is there a use-case for the following two? Added for completeness
        # path + response,
        # path + method,
        path + method + response
      ]
      final_result = {}
      keys_to_search.each do |k|
        setup = @@setups[k]
        if setup
          result = instance_eval &setup
          final_result.merge!(result) if result.is_a?(Hash)
        end
      end
      final_result
    end

    def apivore_build_path(path, data)
{'fraction_non_alphanumeric': 0.09468700683850605, 'fraction_numerical': 0.0, 'mean_word_length': 2.8895705521472395, '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': '5297007', 'n_tokens_mistral': 590, 'n_tokens_neox': 571, 'n_words': 145}