Class: ROM::Finalize::FinalizeMappers

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/setup/finalize/finalize_mappers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mapper_classes, mapper_objects) ⇒ FinalizeMappers

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of FinalizeMappers.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rom/setup/finalize/finalize_mappers.rb', line 9

def initialize(mapper_classes, mapper_objects)
  @mapper_classes = mapper_classes
  @mapper_objects = mapper_objects

  check_duplicate_registered_mappers

  @registry_hash = [@mapper_classes.map(&:base_relation) + @mapper_objects.keys].
                     flatten.
                     uniq.
                     each_with_object({}) { |n, h| h[n] = {} }
end

Instance Attribute Details

#mapper_classesObject (readonly)

Returns the value of attribute mapper_classes.



6
7
8
# File 'lib/rom/setup/finalize/finalize_mappers.rb', line 6

def mapper_classes
  @mapper_classes
end

#mapper_objectsObject (readonly)

Returns the value of attribute mapper_objects.



6
7
8
# File 'lib/rom/setup/finalize/finalize_mappers.rb', line 6

def mapper_objects
  @mapper_objects
end

#registry_hashObject (readonly)

Returns the value of attribute registry_hash.



6
7
8
# File 'lib/rom/setup/finalize/finalize_mappers.rb', line 6

def registry_hash
  @registry_hash
end

Instance Method Details

#run!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rom/setup/finalize/finalize_mappers.rb', line 22

def run!
  cache = Cache.new

  mappers = registry_hash.each_with_object({}) do |(relation_name, relation_mappers), h|
    relation_mappers.update(build_mappers(relation_name))

    if mapper_objects.key?(relation_name)
      relation_mappers.update(mapper_objects[relation_name])
    end

    h[relation_name] = MapperRegistry.new(relation_mappers, cache: cache)
  end

  Registry.new(mappers, cache: cache)
end