Sha256: 3ea75f45e87e4c0e94d6c257b88c742596d87e14273658720a255bf842d5ef43

Contents?: true

Size: 962 Bytes

Versions: 1

Compression:

Stored size: 962 Bytes

Contents

# frozen_string_literal: true

require_relative "core"

module ROM
  module Components
    # @api public
    class Relation < Core
      # @!attribute [r] constant
      #   @return [.new] Relation instance builder (typically a class)
      option :constant, type: Types.Interface(:new)

      # @return [ROM::Relation]
      #
      # @api public
      def build
        constant.use(:changeset)
        constant.use(:registry_reader, relations: registry.relation_ids)

        # Define view methods if there are any registered view components for this relation
        local_components.views(relation_id: id).each do |view|
          view.define(constant)
        end

        apply_plugins

        constant.new(inflector: inflector, registry: registry, **plugin_options)
      end

      # @api public
      def adapter
        config.adapter
      end

      # @api private
      def local_components
        constant.components
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-6.0.0.alpha1 lib/rom/components/relation.rb