lib/nxt_registry/registry.rb in nxt_registry-0.1.0 vs lib/nxt_registry/registry.rb in nxt_registry-0.1.1
- old
+ new
@@ -151,21 +151,21 @@
else
# Call nested registry builder when we are not a leaf
store[key] ||= default.call
end
- resolver.call(value)
- end
+ value = if value.respond_to?(:call) && call && !value.is_a?(NxtRegistry::Registry)
+ value.call(*[value].take(value.arity))
+ else
+ value
+ end
- def setup_defaults(options)
- @default = options.fetch(:default) { Blank.new }
- @memoize = options.fetch(:memoize) { true }
- @call = options.fetch(:call) { true }
- @resolver = options.fetch(:resolver) { ->(value) { value } }
- @transform_keys = options.fetch(:transform_keys) { ->(key) { key.to_s } }
- @on_key_already_registered = options.fetch(:on_key_already_registered) { ->(key) { raise_key_already_registered_error(key) } }
- @on_key_not_registered = options.fetch(:on_key_not_registered) { ->(key) { raise_key_not_registered_error(key) } }
+ if resolver
+ resolver.call(value)
+ else
+ value
+ end
end
def define_interface
define_singleton_method name do |key = Blank.new, value = Blank.new|
return self if key.is_a?(Blank)
@@ -188,9 +188,19 @@
resolve!(key)
else
register!(key, value)
end
end
+ end
+
+ def setup_defaults(options)
+ @default = options.fetch(:default) { Blank.new }
+ @memoize = options.fetch(:memoize) { true }
+ @call = options.fetch(:call) { true }
+ @resolver = options.fetch(:resolver, false)
+ @transform_keys = options.fetch(:transform_keys) { ->(key) { key.to_s } }
+ @on_key_already_registered = options.fetch(:on_key_already_registered) { ->(key) { raise_key_already_registered_error(key) } }
+ @on_key_not_registered = options.fetch(:on_key_not_registered) { ->(key) { raise_key_not_registered_error(key) } }
end
def define_accessors
%w[default memoize call resolver transform_keys on_key_already_registered on_key_not_registered].each do |attribute|
define_singleton_method attribute do |value = Blank.new, &block|