Sha256: dad66850236ff2e4fcfb4ecdffa72c12788ec28d6d7b6bbd76709af8bf85565b

Contents?: true

Size: 575 Bytes

Versions: 1

Compression:

Stored size: 575 Bytes

Contents

require 'dry/importer/version'

module Dry
  module Importer
    module_function

    WRAPPER_MAP = {
      Class  => ->(const) { Class.new(const) },
      Module => ->(const) { Module.new.extend(const) }
    }
    NOOP = ->(const) { const }

    def import(target, namespace)
      namespace.constants(false).each do |constant|
        namespace.const_get(constant).tap do |const|
          ns = target.const_set(constant, WRAPPER_MAP.fetch(const.class, NOOP).call(const))
          import(ns, const) if const.respond_to?(:constants)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-importer-0.0.1 lib/dry/importer.rb