Sha256: c12483552723b470cf9e15abcea977a9df7a9c949d4ccac9a2c839940772b891
Contents?: true
Size: 1.29 KB
Versions: 13
Compression:
Stored size: 1.29 KB
Contents
# frozen_string_literal: true class ReeMapper::MapperFactoryProxy attr_reader :mapper_factory, :register_as, :strategies, :after_build contract( Class, # SubclassOf[ReeMapper::MapperFactory], Kwargs[ register_as: Nilor[Symbol] ], Optblock => Any ) def initialize(mapper_factory, register_as:, &blk) @mapper_factory = mapper_factory @register_as = register_as @strategies = [] @after_build = blk end contract(Or[Symbol, ReeMapper::MapperStrategy], Kwargs[dto: Nilor[Class]], Optblock => Or[ReeMapper::MapperFactoryProxy, ReeMapper::Mapper]).throws(ArgumentError) def use(strategy_or_method, dto: nil, &blk) if strategy_or_method.is_a?(ReeMapper::MapperStrategy) strategy = strategy_or_method else strategy = mapper_factory.find_strategy(strategy_or_method) raise ArgumentError, "MapperFactory strategy :#{strategy_or_method} not found" unless strategy strategy = strategy.dup strategy.dto = dto if dto end self.strategies << strategy return self unless blk mapper = ReeMapper::Mapper.build(strategies) mapper_factory.new(mapper).instance_exec(&blk) mapper.prepare_dto mapper_factory.register_mapper(register_as, mapper) if register_as after_build&.call(mapper) mapper end end
Version data entries
13 entries across 13 versions & 1 rubygems