Sha256: d8605aa667b9724d750f6a3972b41384a4bf5d3c8b1c60df73eeb210a8a0bccb

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require "rom/schema/associations_dsl"
require "rom/relation/name"

require_relative "core"

module ROM
  module Components
    module DSL
      # Setup DSL-specific relation extensions
      #
      # @private
      class Association < Core
        key :associations

        # @api private
        def call
          configure

          backend.instance_eval(&block)

          backend.call.each do |definition|
            components.add(key, definition: definition, config: config.join(definition, :right))
          end
        end

        # @api private
        def backend
          @backend ||= ROM::Schema::AssociationsDSL.new(source, inflector)
        end

        # @api private
        def source
          if provider.config.component.key?(:id)
            # TODO: decouple associations DSL from Relation::Name
            ROM::Relation::Name[
              provider.config.component.id, provider.config.component.dataset
            ]
          else
            config.source
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-6.0.0.alpha1 lib/rom/components/dsl/association.rb