Class: Foobara::Namespace
- Inherits:
-
Object
- Object
- Foobara::Namespace
show all
- Includes:
- IsNamespace
- Defined in:
- foobara-0.1.16/projects/namespace/src/namespace.rb,
foobara-0.1.16/projects/namespace/src/is_namespace.rb,
foobara-0.1.16/projects/namespace/src/base_registry.rb,
foobara-0.1.16/projects/namespace/lib/foobara/namespace.rb,
foobara-0.1.16/projects/namespace/src/namespace_helpers.rb,
foobara-0.1.16/projects/namespace/src/ambiguous_registry.rb,
foobara-0.1.16/projects/namespace/src/prefixless_registry.rb,
foobara-0.1.16/projects/namespace/src/unambiguous_registry.rb,
foobara-0.1.16/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, #unregistered_foobara_manifest_reference
Class Method Summary
collapse
Instance Method Summary
collapse
#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_lookup_without_cache, #foobara_parent_namespace, #foobara_parent_namespace=, #foobara_register, #foobara_registered?, #foobara_registry, #foobara_root?, #foobara_root_namespace, #foobara_unregister, #foobara_unregister_all, #lru_cache, #method_missing, #respond_to_missing?, #scoped_clear_caches, #to_scoped
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_reregistering!, #scoped_short_name, #scoped_short_path, #scoped_unregistered!, #scoped_unregistered?
Constructor Details
#initialize(scoped_name_or_path = nil, parent_namespace: nil) ⇒ Namespace
Returns a new instance of Namespace.
76
77
78
|
# File 'foobara-0.1.16/projects/namespace/src/namespace.rb', line 76
def initialize(scoped_name_or_path = nil, parent_namespace: nil)
NamespaceHelpers.initialize_foobara_namespace(self, scoped_name_or_path, parent_namespace:)
end
|
Class Method Details
.clear_lru_cache! ⇒ Object
69
70
71
|
# File 'foobara-0.1.16/projects/namespace/src/namespace.rb', line 69
def clear_lru_cache!
@lru_cache&.reset!
end
|
.current ⇒ Object
10
11
12
|
# File 'foobara-0.1.16/projects/namespace/src/namespace.rb', line 10
def current
Thread.current[:foobara_current_namespace] || global
end
|
.fire_changed! ⇒ Object
59
60
61
62
63
|
# File 'foobara-0.1.16/projects/namespace/src/namespace.rb', line 59
def fire_changed!
@on_change&.each_pair do |object, method_name|
object.send(method_name)
end
end
|
.global ⇒ Object
6
7
8
|
# File 'foobara-0.1.16/projects/namespace/src/namespace.rb', line 6
def global
@global ||= Namespace.new([])
end
|
.lru_cache ⇒ Object
65
66
67
|
# File 'foobara-0.1.16/projects/namespace/src/namespace.rb', line 65
def lru_cache
@lru_cache ||= Foobara::LruCache.new(1000)
end
|
.on_change(object, method_name) ⇒ Object
53
54
55
56
57
|
# File 'foobara-0.1.16/projects/namespace/src/namespace.rb', line 53
def on_change(object, method_name)
@on_change ||= WeakObjectHash.new
@on_change[object] = method_name
end
|
.to_registry_path(object) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'foobara-0.1.16/projects/namespace/src/namespace.rb', line 35
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
object.split("::")
when Foobara::Scoped
object.scoped_path
else
raise ArgumentError, "Expected #{object} to be a string, symbol, array, or Foobara::IsScoped"
end
end
|
.use(namespace) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'foobara-0.1.16/projects/namespace/src/namespace.rb', line 14
def use(namespace)
unless namespace.is_a?(Namespace::IsNamespace)
raise ArgumentError, "Expected #{namespace} to be a namespace"
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
|