From 5b32cb2b95eb299ce8c8d80dbf39137d70508b61 Mon Sep 17 00:00:00 2001 From: Muhammad Nawzad Date: Mon, 29 Jan 2024 10:53:20 +0300 Subject: [PATCH] Adds `default_value_for_enum_attributes` method to Schemable::Definition --- lib/schemable/definition.rb | 13 +++++++++++++ sig/schemable/definition.rbs | 1 + 2 files changed, 14 insertions(+) diff --git a/lib/schemable/definition.rb b/lib/schemable/definition.rb index 0768f9f..9fb2773 100644 --- a/lib/schemable/definition.rb +++ b/lib/schemable/definition.rb @@ -265,6 +265,19 @@ module Schemable %i[] end + # Returns the default value for the enum attributes. + # + # @example + # { + # status: 'pending', + # flag: 0 + # } + # + # @return [Hash] The custom default values for the enum attributes. + def default_value_for_enum_attributes + {} + end + # Returns an instance of the model class that is already serialized into jsonapi format. # # @return [Hash] The serialized instance of the model class. diff --git a/sig/schemable/definition.rbs b/sig/schemable/definition.rbs index 18db060..64ac8bd 100644 --- a/sig/schemable/definition.rbs +++ b/sig/schemable/definition.rbs @@ -25,6 +25,7 @@ module Schemable def excluded_update_request_attributes: -> Array[Symbol] def optional_create_request_attributes: -> Array[Symbol] def optional_update_request_attributes: -> Array[Symbol] + def default_value_for_enum_attributes: -> Hash[Symbol, any] def additional_create_request_attributes: -> Hash[Symbol, any] def additional_update_request_attributes: -> Hash[Symbol, any] def camelize_keys: (Hash[Symbol, any]) -> (Array[Hash[Symbol, any]] | Hash[Symbol, any])