Sha256: ebba75f2310841d1734a4e90e328dfb3aff5fb75a3338f1449e4dd2162c47bdd

Contents?: true

Size: 941 Bytes

Versions: 10

Compression:

Stored size: 941 Bytes

Contents

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.new(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

10 entries across 10 versions & 1 rubygems

Version Path
rom-core-4.2.1 lib/rom/plugins/relation/registry_reader.rb
rom-core-4.2.0 lib/rom/plugins/relation/registry_reader.rb
rom-core-4.1.2 lib/rom/plugins/relation/registry_reader.rb
rom-core-4.1.1 lib/rom/plugins/relation/registry_reader.rb
rom-core-4.1.0 lib/rom/plugins/relation/registry_reader.rb
rom-core-4.0.2 lib/rom/plugins/relation/registry_reader.rb
rom-core-4.0.1 lib/rom/plugins/relation/registry_reader.rb
rom-core-4.0.0 lib/rom/plugins/relation/registry_reader.rb
rom-core-4.0.0.rc2 lib/rom/plugins/relation/registry_reader.rb
rom-core-4.0.0.rc1 lib/rom/plugins/relation/registry_reader.rb