rail.core.factory_mixin module

class rail.core.factory_mixin.RailFactoryMixin

Bases: object

A Factory can make specific type or types of components, assign names to each, and keep track of what it has made.

This implements:

  1. having a single instance of each sub-class of factory,

  2. having the factory be abble to handle one or more client classes,

  3. creating objects of the sub-classes from yaml,

  4. keeping track of the created object in dictionaries keyed by name,

  5. writing the current content of the factory to a yaml file.

__init__()
Return type:

None

add_dict(configurable_class)

Add a dictionary for one of the client classes

Parameters:

configurable_class (type[C]) – Client class in question

Returns:

Newly created emtpy dict

Return type:

dict[str, C]

Notes

This should be called in the c’tor of the factory for each of the client classes

add_to_dict(the_object)

Add an object one of ‘C’ client class to the corresponding dict

Parameters:

the_object (C) – Object in question

Return type:

None

Notes

This should be called by the factory when inserting objects of the client classes

classmethod clear()

Clear the contents of the factory

Return type:

None

clear_instance()

Clear out the contents of the factory

Return type:

None

client_classes: list[type[Configurable]]
classmethod instance()

Return the singleton instance of the factory

Return type:

T

load_instance_yaml(yaml_file)

Read a yaml file and load the factory accordingly

Parameters:

yaml_file (str) – File to read

Return type:

None

Notes

See class description for yaml file syntax

load_instance_yaml_tag(yaml_config, from_file)

Read a yaml tag and load the factory accordingy

Parameters:
  • yaml_config (list[dict[str, Any]]) – Yaml tag to load

  • from_file (str) – File it was loaded from, used to aviod reloading

Return type:

None

Notes

See class description for yaml file syntax

load_object_from_yaml_tag(configurable_class, yaml_tag)

Create and add an object of one of the client classes from a yaml tag

Parameters:
  • configurable_class (type[C]) – Client class in question

  • yaml_tag (dict[str, Any]) – Yaml used to create the object

Return type:

None

classmethod load_yaml(yaml_file)

Load a yaml file

Parameters:

yaml_file (str) – File to read and load

Return type:

None

Notes

See class helpstring for yaml format

classmethod load_yaml_tag(yaml_config, from_file)

Load from a yaml tag

Parameters:
  • yaml_config (list[dict[str, Any]]) – Yaml tag used to load

  • from_file (str) – File it was loaded from, used to aviod reloading

Return type:

None

Notes

See class helpstring for yaml format

classmethod print_contents()

Print the contents of the factory

Return type:

None

print_instance_contents()

Print the contents of the factory

Return type:

None

to_instance_yaml_dict()

Write the content of the factory to a dict for export to a yaml file

Return type:

dict

classmethod to_yaml_dict()

Construct a dictionary to write to a yaml file

Return type:

dict

classmethod write_yaml(yaml_file)

Write to a yaml file

Parameters:

yaml_file (str) – Yaml file to write

Return type:

None

Notes

See class helpstring for yaml format

yaml_tag: str = ''