Sha256: 4e629297ed72237b888102d4f62bc8d3d64dea487e8b6f74ee6601524b20254d

Contents?: true

Size: 978 Bytes

Versions: 9

Compression:

Stored size: 978 Bytes

Contents

# frozen_string_literal: true

require 'rom/constants'

module ROM
  module Plugins
    module Relation
      # Allows relations to access all other relations through registry
      #
      # For now this plugin is always enabled
      #
      # @api public
      class RegistryReader < ::Module
        EMPTY_REGISTRY = RelationRegistry.build(EMPTY_HASH).freeze

        # @api private
        attr_reader :relations

        # @api private
        def initialize(relations:)
          @relations = relations
          define_readers!
        end

        # @api private
        def included(klass)
          super
          return if klass.instance_methods.include?(:__registry__)

          klass.option :__registry__, default: -> { EMPTY_REGISTRY }
        end

        private

        # @api private
        def define_readers!
          relations.each do |name|
            define_method(name) { __registry__[name] }
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rom-core-5.3.2 lib/rom/plugins/relation/registry_reader.rb
rom-core-5.3.1 lib/rom/plugins/relation/registry_reader.rb
rom-core-5.3.0 lib/rom/plugins/relation/registry_reader.rb
rom-core-5.2.6 lib/rom/plugins/relation/registry_reader.rb
rom-core-5.2.5 lib/rom/plugins/relation/registry_reader.rb
rom-core-5.2.4 lib/rom/plugins/relation/registry_reader.rb
rom-core-5.2.3 lib/rom/plugins/relation/registry_reader.rb
rom-core-5.2.2 lib/rom/plugins/relation/registry_reader.rb
rom-core-5.2.1 lib/rom/plugins/relation/registry_reader.rb