<commit_before># frozen_string_literal: true

module DefaultSpecSchema
  def self.included(base)
    base.extend ClassMethods
  end

  class SchemaMocker
    def initialize(schema)
      @schema = schema
    end

    def type(name, &block)
      superclass = Prelay::Type(schema: @schema)
      c = Class.new(superclass)
      c.name(name.to_s)
      c.model(Kernel.const_get("::#{name}", false))
      c.class_eval(&block)
    end

    def mutation(name, &block)
      superclass = Prelay::Mutation(schema: @schema)
      c = Class.new(superclass)
      c.name(name.to_s)
      c.class_eval(&block)
    end
  end

  module ClassMethods
    def mock_schema(&block)
      before do
        @schema = Prelay::Schema.new(temporary: true)
        SchemaMocker.new(@schema).instance_eval(&block)
      end
    end
  end

  def schema
    @schema || PrelaySpec::SCHEMA
  end

  def mock(thing, schema: Prelay::Schema.new(temporary: true), &block)
    superclass =
      case thing
      when :type      then Prelay::Type(schema: schema)
      when :interface then Prelay::Interface(schema: schema)
      when :query     then Prelay::Query(schema: schema)
      when :mutation  then Prelay::Mutation(schema: schema)
      else raise "Unmockable thing! #{thing.inspect}"<commit_msg>Ensure that mocking schemas doesn't prevent before blocks from running.<commit_after># frozen_string_literal: true

module DefaultSpecSchema
  def self.included(base)
    base.extend ClassMethods
  end

  class SchemaMocker
    def initialize(schema)
      @schema = schema
    end

    def type(name, &block)
      superclass = Prelay::Type(schema: @schema)
      c = Class.new(superclass)
      c.name(name.to_s)
      c.model(Kernel.const_get("::#{name}", false))
      c.class_eval(&block)
    end

    def mutation(name, &block)
      superclass = Prelay::Mutation(schema: @schema)
      c = Class.new(superclass)
      c.name(name.to_s)
      c.class_eval(&block)
    end
  end

  module ClassMethods
    def mock_schema(&block)
      prepend Module.new {
        define_method :setup do
          @schema = Prelay::Schema.new(temporary: true)
          SchemaMocker.new(@schema).instance_eval(&block)
          super()
        end
      }
    end
  end

  def schema
    @schema || PrelaySpec::SCHEMA
  end

  def mock(thing, schema: Prelay::Schema.new(temporary: true), &block)
    superclass =
      case thing
      when :type      then Prelay::Type(schema: schema)
      when :interface then Prelay::Interface(schema: schema)
      when :query     then Prelay::Query(schema: schema)
      when :mutation  then Prelay::Mutation(schema: schema)
      else raise "Unmockable thing! #{thing.inspect}"
{'fraction_non_alphanumeric': 0.10816859380828049, 'fraction_numerical': 0.0, 'mean_word_length': 2.8869565217391306, 'pattern_counts': {'":': 2, '<': 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': '6869941', 'n_tokens_mistral': 868, 'n_tokens_neox': 852, 'n_words': 200}