Describe the bug
Right now default: value is evaluated at the time of declaration, so object is always created. For karafka logger
setting :logger, ::Karafka::Instrumentation::Logger.new
this caused issues with initialization on RO filesystem (1, 2) even if non-default logger was passed.
In waterdrop it's kinda workarounded via
setting(:logger, false) { |logger| logger || Logger.new($stdout, level: Logger::WARN) }
but it's unnecessary complication and with real constructor would be even less readable.
To Reproduce
require 'dry-configurable'
RAISE_EXCEPTION = -> { raise }
class Config
include Dry::Configurable
setting :default_failure, default: RAISE_EXCEPTION.call
end
Expected behavior
Some API that would allow to skip default value initialization if non-default one is passed
require 'dry-configurable'
RAISE_EXCEPTION = -> { raise }
class Config
include Dry::Configurable
setting :default_failure, default: -> { RAISE_EXCEPTION.call }
end
Config.new(default_failure: 'does not fail')
My environment
- Affects my production application: Kinda, PR to karafka was needed
- Ruby version: 3.0.2
- OS: linux
Describe the bug
Right now
default:value is evaluated at the time of declaration, so object is always created. For karafka loggerthis caused issues with initialization on RO filesystem (1, 2) even if non-default logger was passed.
In waterdrop it's kinda workarounded via
but it's unnecessary complication and with real constructor would be even less readable.
To Reproduce
Expected behavior
Some API that would allow to skip default value initialization if non-default one is passed
My environment