Currently, it's not possible to configure a custom StructCompiler because MapperCompiler uses a hard-coded constant. This can be easily changed to use an option with the default value set to StructCompiler.
Examples
This could be configurable on a per-relation basis, with the ability to pre-configure it for all relations from a specific gateway instance.
Setting for all relations in a given gateway
# set it for all relations, this can be handled in `finalize_relations` because we have
# access to gateway instance there
config = ROM::Configuration.new(:sql, 'sqlite::memory', struct_compiler: MyStructCompiler)
rom = ROM.container(config)
Setting per relation
class Users < ROM::Relation[:sql]
# the same method should be used in `finalize_relation` when we set it
# via gateway config
struct_compiler MyStructCompiler
schema(:users, infer: true)
end
TODO
- Tweak
MapperCompiler so that it defines option :struct_compiler, reader: false, default: -> { StructCompiler } and use it in the initialize method options[:struct_compiler].new
- Tweak
FinalizeRelations so that #build_relation uses gateway.options[:struct_compiler] to configure Relation.struct_compiler
- Tweak
Relation.mapper_registry so that it passes configured struct_compiler to the MapperCompiler constructor
Resources
Refs #519
Currently, it's not possible to configure a custom
StructCompilerbecauseMapperCompileruses a hard-coded constant. This can be easily changed to use an option with the default value set toStructCompiler.Examples
This could be configurable on a per-relation basis, with the ability to pre-configure it for all relations from a specific gateway instance.
Setting for all relations in a given gateway
Setting per relation
TODO
MapperCompilerso that it definesoption :struct_compiler, reader: false, default: -> { StructCompiler }and use it in theinitializemethodoptions[:struct_compiler].newFinalizeRelationsso that#build_relationusesgateway.options[:struct_compiler]to configureRelation.struct_compilerRelation.mapper_registryso that it passes configuredstruct_compilerto theMapperCompilerconstructorResources
Refs #519