Skip to content

Commit

Permalink
Add support to lazy options
Browse files Browse the repository at this point in the history
  • Loading branch information
p-lambert committed Oct 16, 2017
1 parent 0ce3796 commit 59d59f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/ddtrace/configuration/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 59d59f3

Please sign in to comment.