Adds Configuration class for global configurations

This commit is contained in:
Muhammad Nawzad 2023-11-09 10:00:47 +03:00
parent 923f3ebe12
commit 01049c4728
No known key found for this signature in database
GPG Key ID: B954B6AAE33940B2
2 changed files with 49 additions and 0 deletions

View File

@ -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

View File

@ -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