Sha256: 2c8db1a8d5350413acf5603de966b339ba1b4e10d2e6628922005cf9fcd1822d

Contents?: true

Size: 958 Bytes

Versions: 3

Compression:

Stored size: 958 Bytes

Contents

# frozen_string_literal: true

module ROM
  class Mapper
    # Setup DSL-specific mapper extensions
    #
    # @private
    class Builder
      # Generate a mapper subclass
      #
      # This is used by Setup#mappers DSL
      #
      # @api private
      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
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rom-core-5.3.2 lib/rom/mapper/builder.rb
rom-core-5.3.1 lib/rom/mapper/builder.rb
rom-core-5.3.0 lib/rom/mapper/builder.rb