# frozen_string_literal: truemoduleMutant# Bootstrap process## The role of the boostrap is to take the pure config and apply it against# the impure world to produce an environment.## env = config interpreted against the world## rubocop:disable Metrics/ModuleLengthmoduleBootstrapincludeAdamantium,Anima.new(:config,:parser,:world)SEMANTICS_MESSAGE_FORMAT="%<message>s. Fix your lib to follow normal ruby semantics!\n"\'{Module,Class}#name should return resolvable constant name as String or nil'CLASS_NAME_RAISED_EXCEPTION='%<scope_class>s#name from: %<scope>s raised an error: %<exception>s'CLASS_NAME_TYPE_MISMATCH_FORMAT='%<scope_class>s#name from: %<raw_scope>s returned %<name>s'private_constant(*constants(false))# Run Bootstrap## @param [Env] env## @return [Either<String, Env>]## rubocop:disable Metrics/MethodLengthdefself.call(env)env.record(:bootstrap)doenv=load_hooks(env).tap(&method(:infect)).with(matchable_scopes: matchable_scopes(env))matched_subjects=env.record(:subject_match)doMatcher.expand(env:).call(env)endselected_subjects=subject_select(env,matched_subjects)mutations=env.record(:mutation_generate)doselected_subjects.flat_map(&:mutations)endsetup_integration(env:,mutations:,selected_subjects:
)endend# rubocop:enable Metrics/MethodLength# Run test only bootstrap## @param [Env] env## @return [Either<String, Env>]defself.call_test(env)env.record(:bootstrap)dosetup_integration(env: load_hooks(env),mutations: [],selected_subjects: [])endend# rubocop:disable Metrics/MethodLength# rubocop:disable Style/MultilineBlockChaindefself.setup_integration(env:,mutations:,selected_subjects:)env.record(__method__)dohooks=env.hookshooks.run(:setup_integration_pre)Integration.setup(env).fmapdo|integration|env.with(integration:,mutations:,selector: Selector::Expression.new(integration:),subjects: selected_subjects)end.tap{hooks.run(:setup_integration_post)}endendprivate_class_method:setup_integration# rubocop:enable Metrics/MethodLength# rubocop:enable Style/MultilineBlockChaindefself.load_hooks(env)env.record(__method__)doenv.with(hooks: Hooks.load_config(env.config))endendprivate_class_method:load_hooksdefself.subject_select(env,subjects)env.record(__method__)dostart_expressions=env.config.matcher.start_expressionsreturnsubjectsifstart_expressions.empty?subjects.drop_whiledo|subject|start_expressions.none?do|expression|expression.prefix?(subject.expression)endendendendprivate_class_method:subject_select# rubocop:disable Metrics/AbcSize# rubocop:disable Metrics/MethodLengthdefself.infect(env)env.record(__method__)doconfig,hooks,world=env.config,env.hooks,env.worldenv.record(:hooks_env_infection_pre)dohooks.run(:env_infection_pre,env:)endenv.record(:require_target)doconfig.environment_variables.eachdo|key,value|world.environment_variables[key]=valueendconfig.includes.each(&world.load_path.public_method(:<<))config.requires.each(&world.kernel.public_method(:require))endenv.record(:hooks_env_infection_post)dohooks.run(:env_infection_post,env:)endendendprivate_class_method:infect# rubocop:enable Metrics/AbcSize# rubocop:enable Metrics/MethodLengthdefself.matchable_scopes(env)env.record(__method__)doconfig=env.configscopes=env.world.object_space.each_object(Module).with_object([])do|raw_scope,aggregate|expression=expression(config.reporter,config.expression_parser,raw_scope)||nextaggregate<<Scope.new(raw: raw_scope,expression:)endscopes.sort_by{|scope|scope.expression.syntax}endendprivate_class_method:matchable_scopesdefself.scope_name(reporter,raw_scope)raw_scope.namerescue=>exceptionsemantics_warning(reporter,CLASS_NAME_RAISED_EXCEPTION,exception: exception.inspect,scope: raw_scope,scope_class: raw_scope.class)nilendprivate_class_method:scope_name# rubocop:disable Metrics/MethodLengthdefself.expression(reporter,expression_parser,raw_scope)name=scope_name(reporter,raw_scope)orreturnunlessname.instance_of?(String)semantics_warning(reporter,CLASS_NAME_TYPE_MISMATCH_FORMAT,name:,scope_class: raw_scope.class,raw_scope:
)returnendexpression_parser.call(name).from_right{}endprivate_class_method:expression# rubocop:enable Metrics/MethodLengthdefself.semantics_warning(reporter,format,options)reporter.warn(SEMANTICS_MESSAGE_FORMAT%{message: format%options})endprivate_class_method:semantics_warningend# Bootstrap# rubocop:enable Metrics/ModuleLengthend# Mutant