From cddc117b473d8d612563bddc947afa85be0df40d Mon Sep 17 00:00:00 2001 From: Muhammad Nawzad Date: Tue, 26 Sep 2023 14:15:16 +0300 Subject: [PATCH] Uses configs to check whether to use string or number for decimal and float types --- lib/schemable.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/schemable.rb b/lib/schemable.rb index 6a17329..41aedfb 100644 --- a/lib/schemable.rb +++ b/lib/schemable.rb @@ -19,8 +19,8 @@ module Schemable text: { type: :string }, string: { type: :string }, integer: { type: :integer }, - float: { type: :number, format: :float }, - decimal: { type: :number, format: :double }, + float: { type: (configs[:float_as_string] ? :string : :number).to_s.to_sym, format: :float }, + decimal: { type: (configs[:decimal_as_string] ? :string : :number).to_s.to_sym, format: :double }, datetime: { type: :string, format: :'date-time' }, date: { type: :string, format: :date }, time: { type: :string, format: :time }, @@ -932,5 +932,15 @@ module Schemable def camelize_keys(hash) hash.deep_transform_keys { |key| key.to_s.camelize(:lower).to_sym } end + + # Returns a json of config options for the definition class. + # + # @return [Hash] The config options for the definition class. + # + # @example + # { decimal_as_string: true } + def configs + {} + end end end