Sha256: d5687870c7eefa6454426fec2a13ba5d4ebb93f1f38fe335f775d5a86b7af11d

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 KB

Contents

require 'rom/support/constants'
require 'rom/configuration_dsl/mapper'

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

      # @api private
      def initialize(registry, mapper_classes, block)
        @registry = registry
        @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 << Mapper.build_class(name, (@mapper_classes + @defined_mappers), options, &block)
        self
      end

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rom-2.0.2 lib/rom/configuration_dsl/mapper_dsl.rb
rom-2.0.1 lib/rom/configuration_dsl/mapper_dsl.rb
rom-2.0.0 lib/rom/configuration_dsl/mapper_dsl.rb
rom-1.0.0 lib/rom/configuration_dsl/mapper_dsl.rb
rom-1.0.0.rc1 lib/rom/configuration_dsl/mapper_dsl.rb
rom-1.0.0.beta2 lib/rom/configuration_dsl/mapper_dsl.rb
rom-1.0.0.beta1 lib/rom/configuration_dsl/mapper_dsl.rb