Sha256: 7e2af3113714d628f38b23ddfd290e2bec20961d75f5e6f35a6b8280207b178b

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

require "dry/rails/railtie"
require "dry/rails/container"
require "dry/rails/components"

module Dry
  # Initializer interface
  #
  # @example set up a container with auto-registration paths
  #   # config/initializer/system.rb
  #
  #   Dry::Rails.container do
  #     config.component_dirs.add "lib" do |dir|
  #       dir.namespaces.add "my_super_cool_app", key: nil
  #     end
  #
  #     config.component_dirs.add "app/operations"
  #   end
  #
  # @api public
  module Rails
    # Set container block that will be evaluated in the context of the container
    #
    # @return [self]
    #
    # @api public
    def self.container(&block)
      _container_blocks << block
      self
    end

    # Create a new container class
    #
    # This is used during booting and reloading
    #
    # @param options [Hash] Container configuration settings
    #
    # @return [Class]
    #
    # @api private
    def self.create_container(options = {})
      Class.new(Container) { config.update(options) }
    end

    # @api private
    def self.evaluate_initializer(container)
      _container_blocks.each do |block|
        container.class_eval(&block)
      end
    end

    # @api private
    def self._container_blocks
      @_container_blocks ||= []
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-rails-0.4.0 lib/dry/rails.rb