Sha256: f1fa734c324d0e43987946fa5e0cf17d0965bd75a92c2c3b501cede87adcac8a

Contents?: true

Size: 613 Bytes

Versions: 14

Compression:

Stored size: 613 Bytes

Contents

module Usable
  module ConfigMulti
    # It's important to define all block specs we need to lazy load
    def +(other)
      config = clone
      specs = other.spec.to_h
      specs.each { |key, val| config[key] = val }
      methods = other.spec.singleton_methods
      methods.map! { |name| name.to_s.tr('=', '').to_sym }
      methods.uniq!
      methods -= specs.keys
      methods.each do |name|
        config.spec.define_singleton_method(name) do
          other.spec.public_method(name).call
        end
        config.instance_variable_get(:@lazy_loads) << name
      end
      config
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
usable-3.10.0 lib/usable/config_multi.rb
usable-3.9.4 lib/usable/config_multi.rb
usable-3.9.3 lib/usable/config_multi.rb
usable-3.9.2 lib/usable/config_multi.rb
usable-3.9.1 lib/usable/config_multi.rb
usable-3.9.0 lib/usable/config_multi.rb
usable-3.8.0 lib/usable/config_multi.rb
usable-3.7.1 lib/usable/config_multi.rb
usable-3.7.0 lib/usable/config_multi.rb
usable-3.6.2 lib/usable/config_multi.rb
usable-3.6.1 lib/usable/config_multi.rb
usable-3.6.0 lib/usable/config_multi.rb
usable-3.5.0 lib/usable/config_multi.rb
usable-3.4.0 lib/usable/config_multi.rb