lib/nxt_registry.rb in nxt_registry-0.3.3 vs lib/nxt_registry.rb in nxt_registry-0.3.4
- old
+ new
@@ -4,10 +4,11 @@
require 'nxt_registry/attribute'
require 'nxt_registry/errors'
require 'nxt_registry/registry_builder'
require 'nxt_registry/registry'
require 'nxt_registry/recursive_registry'
+require 'nxt_registry/singleton'
module NxtRegistry
def registry(name, **options, &config)
build_registry(Registry, name, **options, &config)
end
@@ -17,27 +18,27 @@
end
private
def build_registry(registry_class, name, **options, &config)
- if registries.key?(name)
- registry = registries.fetch(name)
+ registry = registries.resolve(name)
+
+ if registry.present?
if registry.configured
- registry
+ return registry
else
raise_unconfigured_registry_accessed(name)
end
else
registry = registry_class.new(name, **options, &config)
- registries[name] ||= registry
- registry
+ registries.register(name, registry)
end
end
def raise_unconfigured_registry_accessed(name)
raise ArgumentError, "The registry #{name} must be configured before accessed!"
end
def registries
- @registries ||= {}
+ @registries ||= Registry.new(:registries)
end
end