Sha256: cce78a6e4200493985bcd044f79c6dff3a4b6a4c76b8e4eb34551a17dc3c8d33
Contents?: true
Size: 1.23 KB
Versions: 3
Compression:
Stored size: 1.23 KB
Contents
# frozen_string_literal: true module Karafka # Namespace for patches of external gems/libraries module Patches # Patch that will allow to use proc based lazy evaluated settings with Dry Configurable # @see https://github.com/dry-rb/dry-configurable/blob/master/lib/dry/configurable.rb module DryConfigurable # We overwrite ::Dry::Configurable::Config to change on proc behaviour # Unfortunately it does not provide an on call proc evaluation, so # this feature had to be added here on demand/ # @param args Any arguments that DryConfigurable::Config accepts def define!(*args) super.tap { @config.each_key(&method(:rebuild)) } end private # Method that rebuilds a given accessor, so when it consists a proc value, it will # evaluate it upon return for blocks that don't require any arguments, otherwise # it will return the block # @param method_name [Symbol] name of an accessor that we want to rebuild def rebuild(method_name) define_singleton_method method_name do value = super() return value unless value.is_a?(Proc) return value unless value.parameters.empty? value.call end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
karafka-1.2.13 | lib/karafka/patches/dry_configurable.rb |
karafka-1.2.12 | lib/karafka/patches/dry_configurable.rb |
karafka-1.2.11 | lib/karafka/patches/dry_configurable.rb |