Sha256: 24be62a2e1b0c352314a07e373ad57ea3d81cfd9c04bdb3d9af677f2a209be58

Contents?: true

Size: 1.45 KB

Versions: 26

Compression:

Stored size: 1.45 KB

Contents

module Foobara
  class Namespace
    class AmbiguousLookupError < StandardError; end

    class BaseRegistry
      class WouldMakeRegistryAmbiguousError < StandardError; end
      class NotRegisteredError < StandardError; end

      def register(_scoped)
        # :nocov:
        raise "Subclass responsibility"
        # :nocov:
      end

      def registered?(path)
        !lookup(path).nil?
      end

      def unregister(_scoped)
        # :nocov:
        raise "Subclass responsibility"
        # :nocov:
      end

      def lookup(_path, filter: nil)
        # :nocov:
        raise "Subclass responsibility"
        # :nocov:
      end

      # TODO: should return an enumerator
      def each_scoped(filter: nil, &block)
        each_scoped_without_filter do |scoped|
          scoped = apply_filter(scoped, filter) if filter
          block.call(scoped) if scoped
        end
      end

      def all_scoped(filter: nil)
        all = []
        each_scoped(filter:) do |scoped|
          all << scoped
        end
        all
      end

      def each_scoped_without_filter(&)
        # :nocov:
        raise "Subclass responsibility"
        # :nocov:
      end

      def apply_filter(object, filter)
        if filter
          if object.is_a?(::Array)
            object.select { |o| o.instance_eval(&filter) }
          elsif object&.instance_eval(&filter)
            object
          end
        else
          object
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/namespace/src/base_registry.rb
foobara-0.0.25 projects/namespace/src/base_registry.rb
foobara-0.0.24 projects/namespace/src/base_registry.rb
foobara-0.0.23 projects/namespace/src/base_registry.rb
foobara-0.0.22 projects/namespace/src/base_registry.rb
foobara-0.0.21 projects/namespace/src/base_registry.rb
foobara-0.0.20 projects/namespace/src/base_registry.rb
foobara-0.0.19 projects/namespace/src/base_registry.rb
foobara-0.0.18 projects/namespace/src/base_registry.rb
foobara-0.0.17 projects/namespace/src/base_registry.rb
foobara-0.0.16 projects/namespace/src/base_registry.rb
foobara-0.0.15 projects/namespace/src/base_registry.rb
foobara-0.0.14 projects/namespace/src/base_registry.rb
foobara-0.0.13 projects/namespace/src/base_registry.rb
foobara-0.0.12 projects/namespace/src/base_registry.rb
foobara-0.0.11 projects/namespace/src/base_registry.rb
foobara-0.0.10 projects/namespace/src/base_registry.rb
foobara-0.0.9 projects/namespace/src/base_registry.rb
foobara-0.0.8 projects/namespace/src/base_registry.rb
foobara-0.0.7 projects/namespace/src/base_registry.rb