Class: ROM::Mapper::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/mapper/builder.rb

Overview

Setup DSL-specific mapper extensions

Class Method Summary collapse

Class Method Details

.build_class(name, mapper_registry, options = EMPTY_HASH, &block) ⇒ 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.

Generate a mapper subclass

This is used by Setup#mappers DSL



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rom/mapper/builder.rb', line 14

def self.build_class(name, mapper_registry, options = EMPTY_HASH, &block)
  class_name = "ROM::Mapper[#{name}]"

  parent = options[:parent]
  inherit_header = options.fetch(:inherit_header) { ROM::Mapper.inherit_header }

  parent_class =
    if parent
      mapper_registry.detect { |klass| klass.relation == parent }
    else
      ROM::Mapper
    end

  Dry::Core::ClassBuilder.new(name: class_name, parent: parent_class).call do |klass|
    klass.register_as(name)
    klass.relation(name)
    klass.inherit_header(inherit_header)

    klass.class_eval(&block) if block
  end
end