mirror of
https://github.com/ditkrg/schemable.git
synced 2026-01-22 22:26:41 +00:00
Adds Configuration class for global configurations
This commit is contained in:
parent
923f3ebe12
commit
01049c4728
32
lib/schemable/configuration.rb
Normal file
32
lib/schemable/configuration.rb
Normal 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
|
||||
17
sig/schemable/configuration.rbs
Normal file
17
sig/schemable/configuration.rbs
Normal 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
|
||||
Loading…
Reference in New Issue
Block a user