File: namespace.rb

package info (click to toggle)
ruby-dry-container 0.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 236 kB
  • sloc: ruby: 976; makefile: 4
file content (41 lines) | stat: -rw-r--r-- 931 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module Dry
  class Container
    # Create a namespace to be imported
    #
    # @example
    #
    #   ns = Dry::Container::Namespace.new('name') do
    #     register('item', 'item')
    #   end
    #
    #   container = Dry::Container.new
    #
    #   container.import(ns)
    #
    #   container.resolve('name.item')
    #   => 'item'
    #
    #
    # @api public
    class Namespace
      # @return [Mixed] The namespace (name)
      attr_reader :name
      # @return [Proc] The block to be executed when the namespace is imported
      attr_reader :block
      # Create a new namespace
      #
      # @param [Mixed] name
      #   The name of the namespace
      # @yield
      #   The block to evaluate when the namespace is imported
      #
      # @return [Dry::Container::Namespace]
      #
      # @api public
      def initialize(name, &block)
        @name = name
        @block = block
      end
    end
  end
end