Module: Orb::Internal::Type::Union Private
- Includes:
- Converter, Util::SorbetRuntimeSupport
- Included in:
- Models::AdjustmentInterval::Adjustment, Models::Beta::ExternalPlanIDCreatePlanVersionParams::AddAdjustment::Adjustment, Models::Beta::ExternalPlanIDCreatePlanVersionParams::AddPrice::Price, Models::Beta::ExternalPlanIDCreatePlanVersionParams::ReplaceAdjustment::Adjustment, Models::Beta::ExternalPlanIDCreatePlanVersionParams::ReplacePrice::Price, Models::BetaCreatePlanVersionParams::AddAdjustment::Adjustment, Models::BetaCreatePlanVersionParams::AddPrice::Price, Models::BetaCreatePlanVersionParams::ReplaceAdjustment::Adjustment, Models::BetaCreatePlanVersionParams::ReplacePrice::Price, Models::Coupon::Discount, Models::CouponCreateParams::Discount, Models::CustomerCreateParams::TaxConfiguration, Models::CustomerUpdateByExternalIDParams::TaxConfiguration, Models::CustomerUpdateParams::TaxConfiguration, Models::Customers::Credits::LedgerCreateEntryByExternalIDParams::InvoiceSettings::InvoiceDate, Models::Customers::Credits::LedgerCreateEntryByExternalIDResponse, Models::Customers::Credits::LedgerCreateEntryParams::InvoiceSettings::InvoiceDate, Models::Customers::Credits::LedgerCreateEntryResponse, Models::Customers::Credits::LedgerListByExternalIDResponse, Models::Customers::Credits::LedgerListResponse, Models::Discount, Models::EvaluatePriceGroup::GroupingValue, Models::Invoice::LineItem::Adjustment, Models::Invoice::LineItem::SubLineItem, Models::InvoiceFetchUpcomingResponse::LineItem::Adjustment, Models::InvoiceFetchUpcomingResponse::LineItem::SubLineItem, Models::InvoiceLevelDiscount, Models::InvoiceLineItemCreateResponse::Adjustment, Models::InvoiceLineItemCreateResponse::SubLineItem, Models::MutatedSubscription::DiscountInterval, Models::NewFloatingBPSPrice::ConversionRateConfig, Models::NewFloatingBulkBPSPrice::ConversionRateConfig, Models::NewFloatingBulkPrice::ConversionRateConfig, Models::NewFloatingBulkWithProrationPrice::ConversionRateConfig, Models::NewFloatingCumulativeGroupedBulkPrice::ConversionRateConfig, Models::NewFloatingGroupedAllocationPrice::ConversionRateConfig, Models::NewFloatingGroupedTieredPackagePrice::ConversionRateConfig, Models::NewFloatingGroupedTieredPrice::ConversionRateConfig, Models::NewFloatingGroupedWithMeteredMinimumPrice::ConversionRateConfig, Models::NewFloatingGroupedWithProratedMinimumPrice::ConversionRateConfig, Models::NewFloatingMatrixPrice::ConversionRateConfig, Models::NewFloatingMatrixWithAllocationPrice::ConversionRateConfig, Models::NewFloatingMatrixWithDisplayNamePrice::ConversionRateConfig, Models::NewFloatingMaxGroupTieredPackagePrice::ConversionRateConfig, Models::NewFloatingPackagePrice::ConversionRateConfig, Models::NewFloatingPackageWithAllocationPrice::ConversionRateConfig, Models::NewFloatingScalableMatrixWithTieredPricingPrice::ConversionRateConfig, Models::NewFloatingScalableMatrixWithUnitPricingPrice::ConversionRateConfig, Models::NewFloatingThresholdTotalAmountPrice::ConversionRateConfig, Models::NewFloatingTieredBPSPrice::ConversionRateConfig, Models::NewFloatingTieredPackagePrice::ConversionRateConfig, Models::NewFloatingTieredPackageWithMinimumPrice::ConversionRateConfig, Models::NewFloatingTieredPrice::ConversionRateConfig, Models::NewFloatingTieredWithMinimumPrice::ConversionRateConfig, Models::NewFloatingTieredWithProrationPrice::ConversionRateConfig, Models::NewFloatingUnitPrice::ConversionRateConfig, Models::NewFloatingUnitWithPercentPrice::ConversionRateConfig, Models::NewFloatingUnitWithProrationPrice::ConversionRateConfig, Models::NewPlanBPSPrice::ConversionRateConfig, Models::NewPlanBulkBPSPrice::ConversionRateConfig, Models::NewPlanBulkPrice::ConversionRateConfig, Models::NewPlanBulkWithProrationPrice::ConversionRateConfig, Models::NewPlanCumulativeGroupedBulkPrice::ConversionRateConfig, Models::NewPlanGroupedAllocationPrice::ConversionRateConfig, Models::NewPlanGroupedTieredPackagePrice::ConversionRateConfig, Models::NewPlanGroupedTieredPrice::ConversionRateConfig, Models::NewPlanGroupedWithMeteredMinimumPrice::ConversionRateConfig, Models::NewPlanGroupedWithProratedMinimumPrice::ConversionRateConfig, Models::NewPlanMatrixPrice::ConversionRateConfig, Models::NewPlanMatrixWithAllocationPrice::ConversionRateConfig, Models::NewPlanMatrixWithDisplayNamePrice::ConversionRateConfig, Models::NewPlanMaxGroupTieredPackagePrice::ConversionRateConfig, Models::NewPlanPackagePrice::ConversionRateConfig, Models::NewPlanPackageWithAllocationPrice::ConversionRateConfig, Models::NewPlanScalableMatrixWithTieredPricingPrice::ConversionRateConfig, Models::NewPlanScalableMatrixWithUnitPricingPrice::ConversionRateConfig, Models::NewPlanThresholdTotalAmountPrice::ConversionRateConfig, Models::NewPlanTierWithProrationPrice::ConversionRateConfig, Models::NewPlanTieredBPSPrice::ConversionRateConfig, Models::NewPlanTieredPackagePrice::ConversionRateConfig, Models::NewPlanTieredPackageWithMinimumPrice::ConversionRateConfig, Models::NewPlanTieredPrice::ConversionRateConfig, Models::NewPlanTieredWithMinimumPrice::ConversionRateConfig, Models::NewPlanUnitPrice::ConversionRateConfig, Models::NewPlanUnitWithPercentPrice::ConversionRateConfig, Models::NewPlanUnitWithProrationPrice::ConversionRateConfig, Models::NewSubscriptionBPSPrice::ConversionRateConfig, Models::NewSubscriptionBulkBPSPrice::ConversionRateConfig, Models::NewSubscriptionBulkPrice::ConversionRateConfig, Models::NewSubscriptionBulkWithProrationPrice::ConversionRateConfig, Models::NewSubscriptionCumulativeGroupedBulkPrice::ConversionRateConfig, Models::NewSubscriptionGroupedAllocationPrice::ConversionRateConfig, Models::NewSubscriptionGroupedTieredPackagePrice::ConversionRateConfig, Models::NewSubscriptionGroupedTieredPrice::ConversionRateConfig, Models::NewSubscriptionGroupedWithMeteredMinimumPrice::ConversionRateConfig, Models::NewSubscriptionGroupedWithProratedMinimumPrice::ConversionRateConfig, Models::NewSubscriptionMatrixPrice::ConversionRateConfig, Models::NewSubscriptionMatrixWithAllocationPrice::ConversionRateConfig, Models::NewSubscriptionMatrixWithDisplayNamePrice::ConversionRateConfig, Models::NewSubscriptionMaxGroupTieredPackagePrice::ConversionRateConfig, Models::NewSubscriptionPackagePrice::ConversionRateConfig, Models::NewSubscriptionPackageWithAllocationPrice::ConversionRateConfig, Models::NewSubscriptionScalableMatrixWithTieredPricingPrice::ConversionRateConfig, Models::NewSubscriptionScalableMatrixWithUnitPricingPrice::ConversionRateConfig, Models::NewSubscriptionThresholdTotalAmountPrice::ConversionRateConfig, Models::NewSubscriptionTierWithProrationPrice::ConversionRateConfig, Models::NewSubscriptionTieredBPSPrice::ConversionRateConfig, Models::NewSubscriptionTieredPackagePrice::ConversionRateConfig, Models::NewSubscriptionTieredPackageWithMinimumPrice::ConversionRateConfig, Models::NewSubscriptionTieredPrice::ConversionRateConfig, Models::NewSubscriptionTieredWithMinimumPrice::ConversionRateConfig, Models::NewSubscriptionUnitPrice::ConversionRateConfig, Models::NewSubscriptionUnitWithPercentPrice::ConversionRateConfig, Models::NewSubscriptionUnitWithProrationPrice::ConversionRateConfig, Models::Plan::Adjustment, Models::PlanCreateParams::Adjustment::Adjustment, Models::PlanCreateParams::Price::Price, Models::PlanVersion::Adjustment, Models::Price, Models::Price::BPS::ConversionRateConfig, Models::Price::Bulk::ConversionRateConfig, Models::Price::BulkBPS::ConversionRateConfig, Models::Price::BulkWithProration::ConversionRateConfig, Models::Price::CumulativeGroupedBulk::ConversionRateConfig, Models::Price::GroupedAllocation::ConversionRateConfig, Models::Price::GroupedTiered::ConversionRateConfig, Models::Price::GroupedTieredPackage::ConversionRateConfig, Models::Price::GroupedWithMeteredMinimum::ConversionRateConfig, Models::Price::GroupedWithMinMaxThresholds::ConversionRateConfig, Models::Price::GroupedWithProratedMinimum::ConversionRateConfig, Models::Price::Matrix::ConversionRateConfig, Models::Price::MatrixWithAllocation::ConversionRateConfig, Models::Price::MatrixWithDisplayName::ConversionRateConfig, Models::Price::MaxGroupTieredPackage::ConversionRateConfig, Models::Price::Package::ConversionRateConfig, Models::Price::PackageWithAllocation::ConversionRateConfig, Models::Price::ScalableMatrixWithTieredPricing::ConversionRateConfig, Models::Price::ScalableMatrixWithUnitPricing::ConversionRateConfig, Models::Price::ThresholdTotalAmount::ConversionRateConfig, Models::Price::Tiered::ConversionRateConfig, Models::Price::TieredBPS::ConversionRateConfig, Models::Price::TieredPackage::ConversionRateConfig, Models::Price::TieredPackageWithMinimum::ConversionRateConfig, Models::Price::TieredWithMinimum::ConversionRateConfig, Models::Price::TieredWithProration::ConversionRateConfig, Models::Price::Unit::ConversionRateConfig, Models::Price::UnitWithPercent::ConversionRateConfig, Models::Price::UnitWithProration::ConversionRateConfig, Models::PriceCreateParams::ConversionRateConfig, Models::PriceEvaluateMultipleParams::PriceEvaluation::Price, Models::PriceEvaluatePreviewEventsParams::PriceEvaluation::Price, Models::Subscription::DiscountInterval, Models::SubscriptionCreateParams::AddAdjustment::Adjustment, Models::SubscriptionCreateParams::AddPrice::Price, Models::SubscriptionCreateParams::ReplaceAdjustment::Adjustment, Models::SubscriptionCreateParams::ReplacePrice::Price, Models::SubscriptionPriceIntervalsParams::Add::Discount, Models::SubscriptionPriceIntervalsParams::Add::EndDate, Models::SubscriptionPriceIntervalsParams::Add::Price, Models::SubscriptionPriceIntervalsParams::Add::StartDate, Models::SubscriptionPriceIntervalsParams::AddAdjustment::Adjustment, Models::SubscriptionPriceIntervalsParams::AddAdjustment::EndDate, Models::SubscriptionPriceIntervalsParams::AddAdjustment::StartDate, Models::SubscriptionPriceIntervalsParams::Edit::EndDate, Models::SubscriptionPriceIntervalsParams::Edit::StartDate, Models::SubscriptionPriceIntervalsParams::EditAdjustment::EndDate, Models::SubscriptionPriceIntervalsParams::EditAdjustment::StartDate, Models::SubscriptionSchedulePlanChangeParams::AddAdjustment::Adjustment, Models::SubscriptionSchedulePlanChangeParams::AddPrice::Price, Models::SubscriptionSchedulePlanChangeParams::ReplaceAdjustment::Adjustment, Models::SubscriptionSchedulePlanChangeParams::ReplacePrice::Price, Models::SubscriptionUpdateTrialParams::TrialEndDate, Models::SubscriptionUsage
- Defined in:
- lib/orb/internal/type/union.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #===(other) ⇒ Boolean
-
#coerce(value, state:) ⇒ Object
private
Tries to efficiently coerce the given value to one of the known variants.
- #dump(value, state:) ⇒ Object private
- #hash ⇒ Integer
- #inspect(depth: 0) ⇒ String private
- #to_sorbet_type ⇒ Object private
-
#variants ⇒ Array<Object>
private
All of the specified variants for this union.
Methods included from Util::SorbetRuntimeSupport
#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, to_sorbet_type
Methods included from Converter
coerce, dump, inspect, meta_info, new_coerce_state, type_info
Instance Method Details
#==(other) ⇒ Boolean
144 145 146 |
# File 'lib/orb/internal/type/union.rb', line 144 def ==(other) Orb::Internal::Type::Union === other && other.derefed_variants == derefed_variants end |
#===(other) ⇒ Boolean
133 134 135 136 137 |
# File 'lib/orb/internal/type/union.rb', line 133 def ===(other) known_variants.any? do |_, variant_fn| variant_fn.call === other end end |
#coerce(value, state:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Tries to efficiently coerce the given value to one of the known variants.
If the value cannot match any of the known variants, the coercion is considered non-viable and returns the original value.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/orb/internal/type/union.rb', line 175 def coerce(value, state:) if (target = resolve_variant(value)) return Orb::Internal::Type::Converter.coerce(target, value, state: state) end strictness = state.fetch(:strictness) exactness = state.fetch(:exactness) alternatives = [] known_variants.each do |_, variant_fn| target = variant_fn.call exact = state[:exactness] = {yes: 0, no: 0, maybe: 0} state[:branched] += 1 coerced = Orb::Internal::Type::Converter.coerce(target, value, state: state) yes, no, maybe = exact.values if (no + maybe).zero? || (!strictness && yes.positive?) exact.each { exactness[_1] += _2 } state[:exactness] = exactness return coerced elsif maybe.positive? alternatives << [[-yes, -maybe, no], exact, coerced] end end case alternatives.sort_by!(&:first) in [] exactness[:no] += 1 state[:error] = ArgumentError.new("no matching variant for #{value.inspect}") value in [[_, exact, coerced], *] exact.each { exactness[_1] += _2 } coerced end .tap { state[:exactness] = exactness } ensure state[:strictness] = strictness end |
#dump(value, state:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/orb/internal/type/union.rb', line 223 def dump(value, state:) if (target = resolve_variant(value)) return Orb::Internal::Type::Converter.dump(target, value, state: state) end known_variants.each do target = _2.call return Orb::Internal::Type::Converter.dump(target, value, state: state) if target === value end super end |
#hash ⇒ Integer
151 |
# File 'lib/orb/internal/type/union.rb', line 151 def hash = variants.hash |
#inspect(depth: 0) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
259 260 261 262 263 264 265 266 267 268 |
# File 'lib/orb/internal/type/union.rb', line 259 def inspect(depth: 0) if depth.positive? return is_a?(Module) ? super() : self.class.name end members = variants.map { Orb::Internal::Type::Converter.inspect(_1, depth: depth.succ) } prefix = is_a?(Module) ? name : self.class.name "#{prefix}[#{members.join(' | ')}]" end |
#to_sorbet_type ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/orb/internal/type/union.rb', line 239 def to_sorbet_type types = variants.map { Orb::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) }.uniq case types in [] T.noreturn in [type] type else T.any(*types) end end |
#variants ⇒ Array<Object>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
All of the specified variants for this union.
63 |
# File 'lib/orb/internal/type/union.rb', line 63 def variants = derefed_variants.map { _2 } |