Thursday, June 04, 2026 1:46:56 AM
> generator.rb
# frozen_string_literal: true

module Generator
  class << self
    def empty_request_hash
      {base_url: "", url: "", http_verb: "", headers: {}, query: {}, body: {}}
    end

    def empty_expectation_hash
      structure = SpecForge::Normalizer.structures
        # One word: WEEEEEEEE!
        # Not joking, just how the data is set up
        .dig(:spec, :structure, :expectations, :structure, :structure)

      SpecForge::Normalizer.default(structure:, include_optional: true)
        .except(:variables, *empty_request_hash.keys)
    end

    def forge(global: {}, metadata: {}, specs: [])
      specs = specs.map do |spec|
        default_spec = SpecForge::Normalizer.default(:spec, include_optional: true)
        spec = default_spec.deep_merge(spec)

        spec[:id] = SecureRandom.uuid if spec[:id].blank?

        spec[:expectations].map! do |expectation|
          expectation = empty_expectation_hash.merge(expectation)

          expectation[:id] = SecureRandom.uuid if expectation[:id].blank?
          expectation[:expect][:status] = 404 if expectation[:expect][:status].blank?

          expectation
        end

        spec
      end

      SpecForge::Forge.new(global, metadata, specs)
    end
  end
end
All opinions represented herein are my own
- © 2024 - 2026 itsthedevman
- build 4294fb2