Sha256: 91184ba1b8e0ef96ab5649585ed56e658b6325bfe0fa8feda5eb8272125a3947

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require_relative "core"

module ROM
  module Components
    # @api public
    class View < Core
      # @!attribute [r] relation_id
      #   @return [Symbol] Relation runtime identifier
      #   @api private
      option :relation_id

      # @!attribute [r] relation_block
      #   @return [Proc] Block used for view method definition
      #   @api private
      option :relation_block

      # @return [ROM::Relation]
      #
      # @api private
      def build
        registry.relations[relation_id].public_send(config.id)
      end

      # @return [Symbol]
      #
      # @api private
      def define(constant)
        _name = config.id
        _relation_block = relation_block

        if relation_block&.arity&.positive?
          constant.class_eval do
            auto_curry_guard do
              define_method(_name, &_relation_block)

              auto_curry(_name) do
                schemas[_name].(self)
              end
            end
          end
        else
          constant.class_eval do
            define_method(_name) do
              schemas[_name].(instance_eval(&_relation_block))
            end
          end
        end

        _name
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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