Sha256: a37679dc8899a6dc9f434c0fd6509ee2437e55d1462b6313732b86062e729586

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require 'rom/mapper/builder'

module ROM
  class Mapper
    # Mapper definition DSL used by Setup DSL
    #
    # @private
    class MapperDSL
      attr_reader :configuration, :mapper_classes, :defined_mappers

      # @api private
      def initialize(configuration, mapper_classes, block)
        @configuration = configuration
        @mapper_classes = mapper_classes
        @defined_mappers = []

        instance_exec(&block)

        @mapper_classes = @defined_mappers
      end

      # Define a mapper class
      #
      # @param [Symbol] name of the mapper
      # @param [Hash] options
      #
      # @return [Class]
      #
      # @api public
      def define(name, options = EMPTY_HASH, &block)
        @defined_mappers << Builder.build_class(name, (@mapper_classes + @defined_mappers), options, &block)
        self
      end

      # TODO
      #
      # @api public
      def register(relation, mappers)
        configuration.register_mapper(relation => mappers)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rom-core-5.0.2 lib/rom/mapper/mapper_dsl.rb
rom-core-5.0.1 lib/rom/mapper/mapper_dsl.rb
rom-core-5.0.0 lib/rom/mapper/mapper_dsl.rb