Sha256: 4e06c5ccc8effc7a76e53bda51abb5324821b5eb1aaf56684c034429cb9289e4

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

# encoding: utf-8

require 'rom/mapper/builder/definition'

module ROM
  class Mapper

    # Builder DSL for ROM mappers
    #
    class Builder
      attr_reader :schema, :mappers

      # @api public
      def self.call(*args, &block)
        new(*args).call(&block)
      end

      # Initialize a new mapping instance
      #
      # @return [undefined]
      #
      # @api private
      def initialize(schema)
        @schema = schema
        @mappers = {}
      end

      # @api public
      def relation(name, &block)
        definition = Definition.build(schema[name].header, &block)
        mappers[name] = definition.mapper
        self
      end

      # @api private
      def call(&block)
        instance_eval(&block)
      end

      # @api private
      def finalize
        mappers.freeze
      end

      # @api private
      def each(&block)
        mappers.each(&block)
      end

      # @api private
      def [](name)
        mappers.fetch(name)
      end

    end # Builder

  end # Mapper
end # ROM

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-0.2.0 lib/rom/mapper/builder.rb