Sha256: 42be3c2182475d4c0488044ee1caeadea8f8691269049d7f388dd7e99baa4a37

Contents?: true

Size: 632 Bytes

Versions: 4

Compression:

Stored size: 632 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.spec 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

4 entries across 4 versions & 1 rubygems

Version Path
usable-3.1.0 lib/usable/config_multi.rb
usable-3.0.0 lib/usable/config_multi.rb
usable-2.2.1 lib/usable/config_multi.rb
usable-2.2.0 lib/usable/config_multi.rb