Class: Payload::MutableContainer

Inherits:
Object
  • Object
show all
Defined in:
lib/payload/mutable_container.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initialize(container) ⇒ MutableContainer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Used internally by RailsLoader to parse dependency definition files.



12
13
14
15
# File 'lib/payload/mutable_container.rb', line 12

def initialize(container)
  @container = container
  @exported_names = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object

Delegates to Container and uses the returned result as the new container.



22
23
24
25
# File 'lib/payload/mutable_container.rb', line 22

def method_missing(*args, &block)
  @container = @container.send(*args, &block)
  self
end

Instance Method Details

#buildObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Used internally by RailsLoader to return the configured container.

Returns:

  • Container the fully-configured, immutable container.



31
32
33
# File 'lib/payload/mutable_container.rb', line 31

def build
  @container
end

#decorateObject

Delegates to Container and uses the returned result as the new container.



22
23
24
25
# File 'lib/payload/mutable_container.rb', line 22

def method_missing(*args, &block)
  @container = @container.send(*args, &block)
  self
end

#export(*names) ⇒ Object

Exports dependencies so that they are available in other containers.

Parameters:

  • names (Array<Symbol>)

    dependencies to export.



38
39
40
# File 'lib/payload/mutable_container.rb', line 38

def export(*names)
  @exported_names += names
end

#exportsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns dependencies specified by previous #export invocations.

Used internally by RailsLoader.



47
48
49
# File 'lib/payload/mutable_container.rb', line 47

def exports
  @container.export(*@exported_names)
end

#factoryObject

Delegates to Container and uses the returned result as the new container.



22
23
24
25
# File 'lib/payload/mutable_container.rb', line 22

def method_missing(*args, &block)
  @container = @container.send(*args, &block)
  self
end

#serviceObject

Delegates to Container and uses the returned result as the new container.



22
23
24
25
# File 'lib/payload/mutable_container.rb', line 22

def method_missing(*args, &block)
  @container = @container.send(*args, &block)
  self
end