Skip to content

Commit

Permalink
Uses configs to check whether to use string or number for decimal and…
Browse files Browse the repository at this point in the history
… float types
  • Loading branch information
muhammadnawzad committed Sep 26, 2023
1 parent 9f6ecb9 commit cddc117
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/schemable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def type_mapper(type_name)
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 },
Expand Down Expand Up @@ -932,5 +932,15 @@ def self.definitions
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

0 comments on commit cddc117

Please sign in to comment.