Sha256: ed1a41f4ce37b31f4982672301c4f8bcd2d3482c20f7ceb6612d42c3e626529f

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require "rom/relation/name"

require_relative "core"

module ROM
  module Components
    # @api public
    class Schema < Core
      # @api private
      option :name, type: Types.Instance(ROM::Relation::Name), default: -> {
        ROM::Relation::Name[config.relation, config.dataset]
      }

      # @api public
      def build
        if view?
          registry.schemas[config.relation].instance_eval(&block)
        else
          schema = config.constant.define(
            name, **config, **config.options, inferrer: inferrer, registry: registry
          )

          if gateway?
            schema.finalize_attributes!(gateway: gateway)
          else
            schema.finalize_attributes!
          end

          schema.finalize!
        end
      end

      # @api private
      def inferrer
        config.inferrer.with(enabled: config.infer)
      end

      # @api private
      def dataset
        config.dataset
      end

      # @api private
      def adapter
        config.adapter
      end

      # @api private
      def relation
        config.relation
      end

      # @api private
      def view?
        config.view.equal?(true)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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