# frozen_string_literal: truemoduleBundlerclassSettingsclassValidatorclassRuleattr_reader:descriptiondefinitialize(keys,description,&validate)@keys=keys@description=description@validate=validateenddefvalidate!(key,value,settings)instance_exec(key,value,settings,&@validate)enddeffail!(key,value,*reasons)reasons.unshift@descriptionraiseInvalidOption,"Setting `#{key}` to #{value.inspect} failed:\n#{reasons.map{|r|" - #{r}"}.join("\n")}"enddefset(settings,key,value,*reasons)hash_key=k(key)returnifsettings[hash_key]==valuereasons.unshift@descriptionBundler.ui.info"Setting `#{key}` to #{value.inspect}, since #{reasons.join(", ")}"ifvalue.nil?settings.delete(hash_key)elsesettings[hash_key]=valueendenddefk(key)Bundler.settings.key_for(key)endenddefself.rules@rules||=Hash.new{|h,k|h[k]=[]}endprivate_class_method:rulesdefself.rule(keys,description,&blk)rule=Rule.new(keys,description,&blk)keys.each{|k|rules[k]<<rule}endprivate_class_method:ruledefself.validate!(key,value,settings)rules_to_validate=rules[key]rules_to_validate.each{|rule|rule.validate!(key,value,settings)}endrule%w[path path.system],"path and path.system are mutually exclusive"do|key,value,settings|ifkey=="path"&&valueset(settings,"path.system",nil)elsifkey=="path.system"&&valueset(settings,:path,nil)endendrule%w[with without],"a group cannot be in both `with` & `without` simultaneously"do|key,value,settings|with=settings.fetch(k(:with),"").split(":").map(&:to_sym)without=settings.fetch(k(:without),"").split(":").map(&:to_sym)other_key=key=="with"?:without::withother_setting=key=="with"?without:withconflicting=with&withoutifconflicting.any?fail!(key,value,"`#{other_key}` is current set to #{other_setting.inspect}","the `#{conflicting.join("`, `")}` groups conflict")endendendendend