Sha256: 14368c57e5c4670d9d52f626312afdad88092ed0447a8204d97cbc1768ba326d

Contents?: true

Size: 1.56 KB

Versions: 26

Compression:

Stored size: 1.56 KB

Contents

module Foobara
  class Namespace
    include IsNamespace

    class << self
      def global
        @global ||= Namespace.new([])
      end

      def current
        Thread.current[:foobara_current_namespace] || global
      end

      # TODO: eliminate deprecated_namespace and yield instead
      def use(namespace)
        unless namespace.is_a?(Namespace::IsNamespace)
          # :nocov:
          raise ArgumentError, "Expected #{namespace} to be a namespace"
          # :nocov:
        end

        old_namespace = current

        if old_namespace == namespace
          yield
        else
          begin
            Thread.current[:foobara_current_namespace] = namespace
            yield
          ensure
            Thread.current[:foobara_current_namespace] = old_namespace
          end
        end
      end

      def to_registry_path(object)
        return object.map(&:to_s) if object.is_a?(::Array)

        object = object.to_s if object.is_a?(::Symbol)

        case object
        when ::String
          # TODO: Why don't we use symbols instead of strings here?
          object.split("::")
        when Foobara::Scoped
          object.scoped_path
        else
          # :nocov:
          raise ArgumentError, "Expected #{object} to be a string, symbol, array, or Foobara::IsScoped"
          # :nocov:
        end
      end
    end

    class NotFoundError < StandardError; end

    def initialize(scoped_name_or_path = nil, parent_namespace: nil)
      NamespaceHelpers.initialize_foobara_namespace(self, scoped_name_or_path, parent_namespace:)
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

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