Module: Wavix::Internal::Types::Enum
- Includes:
- Type
- Included in:
- CallWebhooks::Types::CallWebhooksCreateRequestEventType, CallWebhooks::Types::DeleteCallWebhooksRequestEventType, Cdrs::Types::CdrSearchRequestType, Profile::Types::ProfileUpdateRequestCompanyInfoIndustry, SmsAndMms::Messages::Types::ListAllMessagesRequestMessageType, SmsAndMms::Messages::Types::ListMessagesRequestMessageType, SmsAndMms::SenderIDs::Types::SenderIDCreateRequestMonthlyVolume, SmsAndMms::SenderIDs::Types::SenderIDCreateRequestUsecase, SubAccounts::Types::ListSubAccountsRequestStatus, SubAccounts::Types::SubAccountsUpdateRequestStatus, TenDlc::BrandAppeals::Types::CreateBrandAppealsRequestAppealCategoriesItem, TenDlc::BrandVettingAppeals::Types::TenDlcBrandVettingAppealCreateRequestAppealCategoriesItem, TenDlc::Brands::Types::QualifyUsecaseBrandsRequestUseCase, TenDlc::Brands::Types::TenDlcBrandUpdateRequestEntityType, TenDlc::Brands::Types::TenDlcBrandUpdateRequestVertical, TenDlc::Campaigns::Types::TenDlcCampaignUpdateRequestUsecase, TwoFa::Verification::Types::TwoFactorVerificationResendRequestChannel, Types::APIKeyCallsScopePermissionAllow, Types::APIKeyScopePermissionAllow, Types::BrandStatusUpdatedWebhookStatus, Types::CallCreateResponseEventType, Types::CallDirection, Types::CallDisposition, Types::CallEventType, Types::CallStatusWebhookDirection, Types::CallStreamChannel, Types::CallStreamType, Types::CallWebhookEventType, Types::CallWebhookListResponseItemEventType, Types::CampaignStatusUpdatedWebhookStatus, Types::CdrTranscriptionCompletedWebhookStatus, Types::DocumentType, Types::MessageDeliveryStatus, Types::NumberStatusUpdatedWebhookStatus, Types::OnCallEventPayloadType, Types::PhoneNumberValidationType, Types::ProfileResponseCompanyInfoIndustry, Types::SenderIDResponseType, Types::SenderIDType, Types::SubOrganizationResponseStatus, Types::TenDlcBrandAppealCreateRequestAppealCategoriesItem, Types::TenDlcBrandCreateRequestEntityType, Types::TenDlcBrandCreateRequestStockExchangeEntityType, Types::TenDlcBrandCreateRequestVertical, Types::TenDlcBrandCreateRequestZeroEntityType, Types::TenDlcBrandEntityType, Types::TenDlcBrandIdentityVerificationStatus, Types::TransactionStatus, Types::TranscriptionLanguage, Types::TranscriptionStatus, Types::TtsLanguage, Types::TtsVoiceID, Types::WhatsAppMessageListItemDirection, Types::WhatsAppMessageListItemStatus, Types::WhatsAppMessageSendRequestTemplateButtonsItemType, Types::WhatsAppMessageSendRequestTemplateHeaderType, Types::WhatsAppMessageStatus, Types::WhatsAppProblemErrorClass, Types::WhatsAppSenderMessageTier, Types::WhatsAppSenderQualityRating, Types::WhatsAppSenderStatus, Types::WhatsAppTemplateCategory, Types::WhatsAppTemplateComponentFormat, Types::WhatsAppTemplateComponentType, Types::WhatsAppTemplateCreateRequestCategory, Types::WhatsAppTemplateQualityRating, Types::WhatsAppTemplateStatus
- Defined in:
- lib/wavix/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/wavix/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/wavix/internal/types/enum.rb', line 18 def finalize! values end |
#inspect ⇒ Object
50 51 52 |
# File 'lib/wavix/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/wavix/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/wavix/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/wavix/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/wavix/internal/types/enum.rb', line 13 def values @values ||= constants.map { |c| const_get(c) } end |