From 59d59f382efce85c92d7d4fa5fc1777337cbed41 Mon Sep 17 00:00:00 2001 From: Pedro Lambert Date: Tue, 3 Oct 2017 16:20:30 -0700 Subject: [PATCH] Add support to lazy options --- lib/ddtrace/configuration/proxy.rb | 6 +++++- test/configuration_test.rb | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/ddtrace/configuration/proxy.rb b/lib/ddtrace/configuration/proxy.rb index 8b904cbe10b..2be1a06d0f1 100644 --- a/lib/ddtrace/configuration/proxy.rb +++ b/lib/ddtrace/configuration/proxy.rb @@ -7,7 +7,11 @@ def initialize(integration) end def [](param) - @integration.get_option(param) + value = @integration.get_option(param) + + return value.call if value.respond_to?(:call) + + value end def []=(param, value) diff --git a/test/configuration_test.rb b/test/configuration_test.rb index a544c34cbb4..28546d7faa0 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -50,6 +50,17 @@ def test_invalid_integration end end + def test_lazy_option + integration = Module.new do + include Contrib::Base + option :option1, default: -> { 1 + 1 } + end + + @registry.add(:example, integration) + + assert_equal(2, @configuration[:example][:option1]) + end + def test_hash_coercion integration = Module.new do include Contrib::Base