Sha256: 175297e2f40a9a455298a3c985db8590153a9c2686d4d64c2772d1520c0fd9d7

Contents?: true

Size: 704 Bytes

Versions: 1

Compression:

Stored size: 704 Bytes

Contents

# frozen_string_literal: true

module ROM
  module Registries
    module Nestable
      # @api public
      def fetch(key, &block)
        if relation_namespace?(key)
          super(namespace, &block)
        elsif relation_scope_key?(key)
          scoped(key)
        else
          super(key, &block)
        end
      end
      alias_method :[], :fetch

      private

      # @api private
      def relation_namespace?(key)
        # TODO: stop nesting canonical mappers under relation's id ie `mappers.users.users`
        path.last == key && !mappers?
      end

      # @api private
      def relation_scope_key?(key)
        !key?(key) && relation_ids.include?(key)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-6.0.0.alpha1 lib/rom/registries/nestable.rb