Sha256: 604f0702cccf2b9a490a4d8ca87970e79000f72ba721f9537ab0ad16de95136a

Contents?: true

Size: 1 KB

Versions: 18

Compression:

Stored size: 1 KB

Contents

require 'rom/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

18 entries across 18 versions & 1 rubygems

Version Path
rom-3.3.3 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.3.2 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.3.1 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.3.0 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.2.3 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.2.2 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.2.1 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.2.0 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.1.0 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.0.3 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.0.2 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.0.1 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.0.0 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.0.0.rc2 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.0.0.rc1 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.0.0.beta3 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.0.0.beta2 lib/rom/setup/finalize/finalize_mappers.rb
rom-3.0.0.beta1 lib/rom/setup/finalize/finalize_mappers.rb