Module: Square::Internal::Types::Enum
- Includes:
- Type
- Included in:
- Types::ActionCancelReason, Types::ActivityType, Types::ApplicationDetailsExternalSquareProduct, Types::ArchivedState, Types::BankAccountStatus, Types::BankAccountType, Types::BookingBookingSource, Types::BookingCreatorDetailsCreatorType, Types::BookingStatus, Types::BusinessAppointmentSettingsAlignmentTime, Types::BusinessAppointmentSettingsBookingLocationType, Types::BusinessAppointmentSettingsCancellationPolicy, Types::BusinessAppointmentSettingsMaxAppointmentsPerDayLimitType, Types::BusinessBookingProfileBookingPolicy, Types::BusinessBookingProfileCustomerTimezoneChoice, Types::CardBrand, Types::CardCoBrand, Types::CardPrepaidType, Types::CardType, Types::CashDrawerEventType, Types::CashDrawerShiftState, Types::CatalogCategoryType, Types::CatalogCustomAttributeDefinitionAppVisibility, Types::CatalogCustomAttributeDefinitionSellerVisibility, Types::CatalogCustomAttributeDefinitionType, Types::CatalogDiscountModifyTaxBasis, Types::CatalogDiscountType, Types::CatalogItemFoodAndBeverageDetailsDietaryPreferenceStandardDietaryPreference, Types::CatalogItemFoodAndBeverageDetailsDietaryPreferenceType, Types::CatalogItemFoodAndBeverageDetailsIngredientStandardIngredient, Types::CatalogItemProductType, Types::CatalogModifierListModifierType, Types::CatalogModifierListSelectionType, Types::CatalogModifierToggleOverrideType, Types::CatalogObjectType, Types::CatalogPricingType, Types::CatalogQuickAmountType, Types::CatalogQuickAmountsSettingsOption, Types::ChangeTiming, Types::ChannelStatus, Types::CheckoutLocationSettingsBrandingButtonShape, Types::CheckoutLocationSettingsBrandingHeaderType, Types::CheckoutOptionsPaymentType, Types::ComponentComponentType, Types::Country, Types::Currency, Types::CustomAttributeDefinitionVisibility, Types::CustomerCreationSource, Types::CustomerInclusionExclusion, Types::CustomerSortField, Types::DataCollectionOptionsInputType, Types::DayOfWeek, Types::DestinationType, Types::DeviceAttributesDeviceType, Types::DeviceCodeStatus, Types::DeviceComponentDetailsExternalPower, Types::DeviceStatusCategory, Types::DisputeEvidenceType, Types::DisputeReason, Types::DisputeState, Types::EcomVisibility, Types::EmployeeStatus, Types::ErrorCategory, Types::ErrorCode, Types::ExcludeStrategy, Types::FulfillmentDeliveryDetailsOrderFulfillmentDeliveryDetailsScheduleType, Types::FulfillmentFulfillmentLineItemApplication, Types::FulfillmentPickupDetailsScheduleType, Types::FulfillmentState, Types::FulfillmentType, Types::GiftCardActivityAdjustDecrementReason, Types::GiftCardActivityAdjustIncrementReason, Types::GiftCardActivityClearBalanceReason, Types::GiftCardActivityDeactivateReason, Types::GiftCardActivityRedeemStatus, Types::GiftCardActivityType, Types::GiftCardGanSource, Types::GiftCardStatus, Types::GiftCardType, Types::InventoryAlertType, Types::InventoryChangeType, Types::InventoryState, Types::InvoiceAutomaticPaymentSource, Types::InvoiceCustomFieldPlacement, Types::InvoiceDeliveryMethod, Types::InvoicePaymentReminderStatus, Types::InvoiceRequestMethod, Types::InvoiceRequestType, Types::InvoiceStatus, Types::JobAssignmentPayType, Types::ListPaymentRefundsRequestSortField, Types::ListPaymentsRequestSortField, Types::LocationCapability, Types::LocationStatus, Types::LocationType, Types::LoyaltyEventSource, Types::LoyaltyEventType, Types::LoyaltyProgramAccrualRuleTaxMode, Types::LoyaltyProgramAccrualRuleType, Types::LoyaltyProgramStatus, Types::LoyaltyPromotionIncentiveType, Types::LoyaltyPromotionStatus, Types::LoyaltyPromotionTriggerLimitInterval, Types::LoyaltyRewardStatus, Types::MeasurementUnitArea, Types::MeasurementUnitLength, Types::MeasurementUnitTime, Types::MeasurementUnitUnitType, Types::MeasurementUnitVolume, Types::MeasurementUnitWeight, Types::MerchantStatus, Types::OauthAuthorizationRevokedEventRevokerType, Types::OrderCardSurchargeTreatmentType, Types::OrderFulfillmentDeliveryDetailsScheduleType, Types::OrderFulfillmentFulfillmentLineItemApplication, Types::OrderFulfillmentPickupDetailsScheduleType, Types::OrderFulfillmentState, Types::OrderFulfillmentType, Types::OrderLineItemDiscountScope, Types::OrderLineItemDiscountType, Types::OrderLineItemItemType, Types::OrderLineItemTaxScope, Types::OrderLineItemTaxType, Types::OrderServiceChargeCalculationPhase, Types::OrderServiceChargeScope, Types::OrderServiceChargeTreatmentType, Types::OrderServiceChargeType, Types::OrderState, Types::PaymentOptionsDelayAction, Types::PayoutFeeType, Types::PayoutStatus, Types::PayoutType, Types::Product, Types::ReferenceType, Types::RefundStatus, Types::RegisterDomainResponseStatus, Types::RiskEvaluationRiskLevel, Types::ScheduledShiftFilterAssignmentStatus, Types::ScheduledShiftFilterScheduledShiftStatus, Types::ScheduledShiftNotificationAudience, Types::ScheduledShiftSortField, Types::ScheduledShiftWorkdayMatcher, Types::SearchCatalogItemsRequestStockLevel, Types::SearchOrdersSortField, Types::SearchVendorsRequestSortField, Types::ShiftFilterStatus, Types::ShiftSortField, Types::ShiftStatus, Types::ShiftWorkdayMatcher, Types::SortOrder, Types::SubscriptionActionType, Types::SubscriptionCadence, Types::SubscriptionEventInfoCode, Types::SubscriptionEventSubscriptionEventType, Types::SubscriptionPricingType, Types::SubscriptionStatus, Types::TaxCalculationPhase, Types::TaxInclusionType, Types::TeamMemberAssignedLocationsAssignmentType, Types::TeamMemberInvitationStatus, Types::TeamMemberStatus, Types::TenderBankAccountDetailsStatus, Types::TenderBuyNowPayLaterDetailsBrand, Types::TenderBuyNowPayLaterDetailsStatus, Types::TenderCardDetailsEntryMethod, Types::TenderCardDetailsStatus, Types::TenderSquareAccountDetailsStatus, Types::TenderType, Types::TerminalActionActionType, Types::TimecardFilterStatus, Types::TimecardSortField, Types::TimecardStatus, Types::TimecardWorkdayMatcher, Types::TransactionProduct, Types::TransactionType, Types::TransferOrderSortField, Types::TransferOrderStatus, Types::V1OrderHistoryEntryAction, Types::V1OrderState, Types::V1TenderCardBrand, Types::V1TenderEntryMethod, Types::V1TenderType, Types::V1UpdateOrderRequestAction, Types::VendorStatus, Types::VisibilityFilter, Types::Weekday
- Defined in:
- lib/square/internal/types/enum.rb
Overview
Module for defining enums
Instance Method Summary collapse
- #coerce(value, strict: strict?) ) ⇒ Object
- #finalize! ⇒ Object private
- #inspect ⇒ Object
-
#load(str) ⇒ String
Parse JSON string and coerce to the enum value.
- #strict! ⇒ Object private
- #strict? ⇒ Boolean private
- #values ⇒ Array<Object> private
Methods included from JSON::Serializable
Instance Method Details
#coerce(value, strict: strict?) ) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/square/internal/types/enum.rb', line 32 def coerce(value, strict: strict?) coerced_value = Utils.coerce(Symbol, value) return coerced_value if values.include?(coerced_value) raise Errors::TypeError, "`#{value}` not in enum #{self}" if strict value end |
#finalize! ⇒ 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.
18 19 20 |
# File 'lib/square/internal/types/enum.rb', line 18 def finalize! values end |
#inspect ⇒ Object
50 51 52 |
# File 'lib/square/internal/types/enum.rb', line 50 def inspect "#{name}[#{values.join(", ")}]" end |
#load(str) ⇒ String
Parse JSON string and coerce to the enum value
46 47 48 |
# File 'lib/square/internal/types/enum.rb', line 46 def load(str) coerce(::JSON.parse(str)) end |
#strict! ⇒ 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.
28 29 30 |
# File 'lib/square/internal/types/enum.rb', line 28 def strict! @strict = true end |
#strict? ⇒ Boolean
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.
23 24 25 |
# File 'lib/square/internal/types/enum.rb', line 23 def strict? @strict ||= false end |
#values ⇒ 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.
13 14 15 |
# File 'lib/square/internal/types/enum.rb', line 13 def values @values ||= constants.map { |c| const_get(c) } end |