class Payload::MutableContainer

Mutable builder for defining dependencies.

Allows defining dependencies without fear of breaking the chain while still encapsulating mutation in one location.

Decorates a {Container} and delegates definition calls.

Public Class Methods

new(container) click to toggle source

Used internally by {RailsLoader} to parse dependency definition files.

@api private

# File lib/payload/mutable_container.rb, line 12
def initialize(container)
  @container = container
  @exported_names = []
end

Public Instance Methods

build() click to toggle source

Used internally by {RailsLoader} to return the configured container.

@api private @return Container the fully-configured, immutable container.

# File lib/payload/mutable_container.rb, line 31
def build
  @container
end
export(*names) click to toggle source

Exports dependencies so that they are available in other containers.

@param names [Array<Symbol>] dependencies to export.

# File lib/payload/mutable_container.rb, line 38
def export(*names)
  @exported_names += names
end
exports() click to toggle source

Returns dependencies specified by previous {#export} invocations.

Used internally by {RailsLoader}.

@api private

# File lib/payload/mutable_container.rb, line 47
def exports
  @container.export(*@exported_names)
end
method_missing(*args, &block) click to toggle source

Delegates to {Container} and uses the returned result as the new container. @!method decorate @!method factory @!method service

# File lib/payload/mutable_container.rb, line 22
def method_missing(*args, &block)
  @container = @container.send(*args, &block)
  self
end

Private Instance Methods

respond_to_missing?(*args) click to toggle source
# File lib/payload/mutable_container.rb, line 53
def respond_to_missing?(*args)
  @container.respond_to?(*args)
end