Sha256: 236ee101823f6fad200acb60b5540dac86ceab363150b990ffe23b78e7aa45e7

Contents?: true

Size: 624 Bytes

Versions: 2

Compression:

Stored size: 624 Bytes

Contents

module Usable
  module ConfigMulti
    # It's important to define all block specs we need to lazy load
    # Set block specs to nil values so it will fallback to calling the underlying singleton method defined by Config#method_missing
    def +(other)
      config = clone
      specs = other.spec.to_h
      specs.each { |key, val| config[key] = val }
      methods = other.spec.singleton_methods - specs.keys
      methods.each do |name|
        config.spec[name] = nil
        config.spec.define_singleton_method(name) do
          other.spec.public_method(name).call
        end
      end
      config
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
usable-3.3.0 lib/usable/config_multi.rb
usable-3.2.0 lib/usable/config_multi.rb