Class: Foobara::Namespace
- Inherits:
-
Object
- Object
- Foobara::Namespace
- Includes:
- IsNamespace
- Defined in:
- foobara-0.0.110/projects/namespace/src/namespace.rb,
foobara-0.0.110/projects/namespace/src/is_namespace.rb,
foobara-0.0.110/projects/namespace/src/base_registry.rb,
foobara-0.0.110/projects/namespace/lib/foobara/namespace.rb,
foobara-0.0.110/projects/namespace/src/namespace_helpers.rb,
foobara-0.0.110/projects/namespace/src/ambiguous_registry.rb,
foobara-0.0.110/projects/namespace/src/prefixless_registry.rb,
foobara-0.0.110/projects/namespace/src/unambiguous_registry.rb,
foobara-0.0.110/projects/namespace/src/namespace/lookup_mode.rb
Defined Under Namespace
Modules: IsNamespace, LookupMode, NamespaceHelpers Classes: AmbiguousLookupError, AmbiguousRegistry, BaseRegistry, NotFoundError, PrefixlessRegistry, UnambiguousRegistry
Instance Attribute Summary
Attributes included from Scoped
#foobara_manifest_reference, #scoped_namespace
Class Method Summary collapse
- .current ⇒ Object
- .global ⇒ Object
- .to_registry_path(object) ⇒ Object
-
.use(namespace) ⇒ Object
TODO: eliminate deprecated_namespace and yield instead.
Instance Method Summary collapse
-
#initialize(scoped_name_or_path = nil, parent_namespace: nil) ⇒ Namespace
constructor
A new instance of Namespace.
Methods included from IsNamespace
#foobara_add_category, #foobara_add_category_for_instance_of, #foobara_add_category_for_subclass_of, #foobara_all, #foobara_categories, #foobara_category_symbol_for, #foobara_children, #foobara_depends_on_namespaces, #foobara_each, #foobara_lookup, #foobara_lookup!, #foobara_parent_namespace, #foobara_parent_namespace=, #foobara_register, #foobara_registered?, #foobara_registry, #foobara_root?, #foobara_root_namespace, #foobara_unregister, #method_missing, #respond_to_missing?, #scoped_clear_caches
Methods included from Scoped
#scoped_absolute_name, #scoped_category, #scoped_clear_caches, #scoped_full_name, #scoped_full_path, #scoped_ignore_module?, #scoped_ignore_modules=, #scoped_name, #scoped_name=, #scoped_path, #scoped_path=, #scoped_path_autoset=, #scoped_path_autoset?, #scoped_path_set?, #scoped_prefix, #scoped_short_name, #scoped_short_path
Constructor Details
#initialize(scoped_name_or_path = nil, parent_namespace: nil) ⇒ Namespace
Returns a new instance of Namespace.
57 58 59 |
# File 'foobara-0.0.110/projects/namespace/src/namespace.rb', line 57 def initialize(scoped_name_or_path = nil, parent_namespace: nil) NamespaceHelpers.(self, scoped_name_or_path, parent_namespace:) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Foobara::Namespace::IsNamespace
Class Method Details
.current ⇒ Object
10 11 12 |
# File 'foobara-0.0.110/projects/namespace/src/namespace.rb', line 10 def current Thread.current[:foobara_current_namespace] || global end |
.global ⇒ Object
6 7 8 |
# File 'foobara-0.0.110/projects/namespace/src/namespace.rb', line 6 def global @global ||= Namespace.new([]) end |
.to_registry_path(object) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'foobara-0.0.110/projects/namespace/src/namespace.rb', line 36 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 |
.use(namespace) ⇒ Object
TODO: eliminate deprecated_namespace and yield instead
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'foobara-0.0.110/projects/namespace/src/namespace.rb', line 15 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 |