diff --git a/lib/schemable/configuration.rb b/lib/schemable/configuration.rb new file mode 100644 index 0000000..97e75b9 --- /dev/null +++ b/lib/schemable/configuration.rb @@ -0,0 +1,32 @@ +# configuration.rb +module Schemable + class Configuration + attr_accessor( + :orm, + :timestamps, + :float_as_string, + :decimal_as_string, + :custom_type_mappers, + :disable_factory_bot + ) + + def initialize + @timestamps = true + @orm = :active_record # orm options are :active_record, :mongoid + @float_as_string = false + @custom_type_mappers = {} + @decimal_as_string = false + @disable_factory_bot = true + end + + def type_mapper(type_name) + return @custom_type_mappers[type_name] if @custom_type_mappers.key?(type_name) + + TYPES_MAP[type_name.try(:to_sym)] + end + + def add_custom_type_mapper(type_name, mapping) + custom_type_mappers[type_name.to_sym] = mapping + end + end +end diff --git a/sig/schemable/configuration.rbs b/sig/schemable/configuration.rbs new file mode 100644 index 0000000..af84948 --- /dev/null +++ b/sig/schemable/configuration.rbs @@ -0,0 +1,17 @@ +module Schemable + class Configuration + attr_accessor disable_factory_bot: untyped + attr_accessor orm: Symbol + attr_accessor timestamps: bool + attr_accessor float_as_string: bool + attr_accessor decimal_as_string: bool + attr_accessor disable_factory_bot: bool + attr_accessor custom_type_mappers: Hash[Symbol, Symbol | Object] + + def initialize: -> void + + def add_custom_type_mapper: (Symbol, Hash[Symbol, Symbol | Object]) -> void + + def type_mapper: (Symbol) -> Hash[Symbol, Symbol | Object] + end +end