# frozen_string_literal: truemoduleOnebusawaySDKmoduleInternalmoduleType# @api privatemoduleConverterextendOnebusawaySDK::Internal::Util::SorbetRuntimeSupport# rubocop:disable Lint/UnusedMethodArgument# @api private## @param value [Object]## @param state [Hash{Symbol=>Object}] .## @option state [Boolean] :translate_names## @option state [Boolean] :strictness## @option state [Hash{Symbol=>Object}] :exactness## @option state [Class<StandardError>] :error## @option state [Integer] :branched## @return [Object]defcoerce(value,state:)=(raiseNotImplementedError)# @api private## @param value [Object]## @param state [Hash{Symbol=>Object}] .## @option state [Boolean] :can_retry## @return [Object]defdump(value,state:)casevalueinArrayvalue.map{OnebusawaySDK::Internal::Type::Unknown.dump(_1,state: state)}inHashvalue.transform_values{OnebusawaySDK::Internal::Type::Unknown.dump(_1,state: state)}inOnebusawaySDK::Internal::Type::BaseModelvalue.class.dump(value,state: state)inStringIOvalue.stringinPathname|IOstate[:can_retry]=falseifvalue.is_a?(IO)OnebusawaySDK::FilePart.new(value)inOnebusawaySDK::FilePartstate[:can_retry]=falseifvalue.content.is_a?(IO)valueelsevalueendend# @api private## @param depth [Integer]## @return [String]definspect(depth: 0)super()end# rubocop:enable Lint/UnusedMethodArgumentclass<<self# @api private## @param spec [Hash{Symbol=>Object}, Proc, OnebusawaySDK::Internal::Type::Converter, Class] .## @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const## @option spec [Proc] :enum## @option spec [Proc] :union## @option spec [Boolean] :"nil?"## @return [Proc]deftype_info(spec)casespecinProcspecinHashtype_info(spec.slice(:const,:enum,:union).first&.last)intrue|false->{OnebusawaySDK::Internal::Type::Boolean}inOnebusawaySDK::Internal::Type::Converter|Class|Symbol->{spec}inNilClass|Integer|Float->{spec.class}endend# @api private## @param translate_names [Boolean]## @return [Hash{Symbol=>Object}]defnew_coerce_state(translate_names: true){translate_names: translate_names,strictness: true,exactness: {yes: 0,no: 0,maybe: 0},error: nil,branched: 0}end# @api private## Based on `target`, transform `value` into `target`, to the extent possible:## 1. if the given `value` conforms to `target` already, return the given `value`# 2. if it's possible and safe to convert the given `value` to `target`, then the# converted value# 3. otherwise, the given `value` unaltered## The coercion process is subject to improvement between minor release versions.# See https://docs.pydantic.dev/latest/concepts/unions/#smart-mode## @param target [OnebusawaySDK::Internal::Type::Converter, Class]## @param value [Object]## @param state [Hash{Symbol=>Object}] The `strictness` is one of `true`, `false`. This informs the coercion strategy# when we have to decide between multiple possible conversion targets:## - `true`: the conversion must be exact, with minimum coercion.# - `false`: the conversion can be approximate, with some coercion.## The `exactness` is `Hash` with keys being one of `yes`, `no`, or `maybe`. For# any given conversion attempt, the exactness will be updated based on how closely# the value recursively matches the target type:## - `yes`: the value can be converted to the target type with minimum coercion.# - `maybe`: the value can be converted to the target type with some reasonable# coercion.# - `no`: the value cannot be converted to the target type.## See implementation below for more details.## @option state [Boolean] :translate_names## @option state [Boolean] :strictness## @option state [Hash{Symbol=>Object}] :exactness## @option state [Class<StandardError>] :error## @option state [Integer] :branched## @return [Object]defcoerce(target,value,state: OnebusawaySDK::Internal::Type::Converter.new_coerce_state)# rubocop:disable Metrics/BlockNestingexactness=state.fetch(:exactness)casetargetinOnebusawaySDK::Internal::Type::Converterreturntarget.coerce(value,state: state)inClassifvalue.is_a?(target)exactness[:yes]+=1returnvalueendcasetargetin->{_1<=NilClass}exactness[value.nil??:yes::maybe]+=1returnnilin->{_1<=Integer}casevalueinIntegerexactness[:yes]+=1returnvalueelseKernel.thendoreturnInteger(value).tap{exactness[:maybe]+=1}rescueArgumentError,TypeError=>estate[:error]=eendendin->{_1<=Float}ifvalue.is_a?(Numeric)exactness[:yes]+=1returnFloat(value)elseKernel.thendoreturnFloat(value).tap{exactness[:maybe]+=1}rescueArgumentError,TypeError=>estate[:error]=eendendin->{_1<=String}casevalueinString|Symbol|Numericexactness[value.is_a?(Numeric)?:maybe::yes]+=1returnvalue.to_sinStringIOexactness[:yes]+=1returnvalue.stringelsestate[:error]=TypeError.new("#{value.class} can't be coerced into #{String}")endin->{_1<=Date||_1<=Time}Kernel.thendoreturntarget.parse(value).tap{exactness[:yes]+=1}rescueArgumentError,TypeError=>estate[:error]=eendin->{_1<=StringIO}ifvalue.is_a?(String)exactness[:yes]+=1returnStringIO.new(value.b)elseendinSymbolcasevalueinSymbol|Stringifvalue.to_sym==targetexactness[:yes]+=1returntargetelseexactness[:maybe]+=1returnvalueendelsemessage="cannot convert non-matching #{value.class} into #{target.inspect}"state[:error]=ArgumentError.new(message)endelseendexactness[:no]+=1value# rubocop:enable Metrics/BlockNestingend# @api private## @param target [OnebusawaySDK::Internal::Type::Converter, Class]## @param value [Object]## @param state [Hash{Symbol=>Object}] .## @option state [Boolean] :can_retry## @return [Object]defdump(target,value,state: {can_retry: true})casetargetinOnebusawaySDK::Internal::Type::Convertertarget.dump(value,state: state)elseOnebusawaySDK::Internal::Type::Unknown.dump(value,state: state)endend# @api private## @param target [Object]# @param depth [Integer]## @return [String]definspect(target,depth:)casetargetinOnebusawaySDK::Internal::Type::Convertertarget.inspect(depth: depth.succ)elsetarget.inspectendendenddefine_sorbet_constant!(:Input)doT.type_alias{T.any(OnebusawaySDK::Internal::Type::Converter,T::Class[T.anything])}enddefine_sorbet_constant!(:CoerceState)doT.type_aliasdo{translate_names: T::Boolean,strictness: T::Boolean,exactness: {yes: Integer,no: Integer,maybe: Integer},error: T::Class[StandardError],branched: Integer}endenddefine_sorbet_constant!(:DumpState)doT.type_alias{{can_retry: T::Boolean}}endendendendend