Sha256: 154d8c25296c913640d7e534545c3f4cfae55bf78bd928a1fbcc944d31c2fbf5

Contents?: true

Size: 814 Bytes

Versions: 1

Compression:

Stored size: 814 Bytes

Contents

module Dry
  class Container
    # @api private
    class NamespaceDSL < ::SimpleDelegator
      def initialize(container, namespace, namespace_separator, &block)
        @namespace = namespace
        @namespace_separator = namespace_separator

        super(container)

        if block.arity.zero?
          instance_eval(&block)
        else
          block.call(self)
        end
      end

      def register(key, *args, &block)
        super(namespaced(key), *args, &block)
      end

      def namespace(namespace, &block)
        super(namespaced(namespace), &block)
      end

      def import(namespace)
        namespace(namespace.name, &namespace.block)

        self
      end

      private

      def namespaced(key)
        [@namespace, key].join(@namespace_separator)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-container-0.2.2 lib/dry/container/namespace_dsl.rb