Sha256: 73c12113048de2c7c31eb793dd7ec70ed50b32989a3d91814ae6d3531415cd28

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 KB

Contents

require 'rom/support/registry'

module ROM
  class Finalize
    class FinalizeMappers
      # @api private
      def initialize(mapper_classes, mapper_objects)
        @mapper_classes = mapper_classes
        @mapper_objects = mapper_objects
      end

      # @api private
      def run!
        registry = @mapper_classes.each_with_object({}) do |klass, h|
          name = klass.register_as || klass.relation
          (h[klass.base_relation] ||= {})[name] = klass.build
        end

        registry_hash = registry.each_with_object({}).each { |(relation, mappers), h|
          h[relation] = MapperRegistry.new(mappers)
        }

        @mapper_objects.each do |relation, mappers|
          if registry_hash.key?(relation)
            mappers_registry = registry_hash[relation]
            mappers.each { |name, mapper| mappers_registry[name] = mapper }
          else
            registry_hash[relation] = MapperRegistry.new(mappers)
          end
        end

        Registry.new(registry_hash)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rom-2.0.2 lib/rom/setup/finalize/finalize_mappers.rb
rom-2.0.1 lib/rom/setup/finalize/finalize_mappers.rb
rom-2.0.0 lib/rom/setup/finalize/finalize_mappers.rb
rom-1.0.0 lib/rom/setup/finalize/mappers.rb
rom-1.0.0.rc1 lib/rom/setup/finalize/mappers.rb
rom-1.0.0.beta2 lib/rom/setup/finalize/mappers.rb
rom-1.0.0.beta1 lib/rom/setup/finalize/mappers.rb