rail.projects.factory_mixin module
- class rail.projects.factory_mixin.RailFactoryMixin[source]
Bases:
objectA Factory can make specific type or types of components, assign names to each, and keep track of what it has made.
This implements:
having a single instance of each sub-class of factory,
having the factory be abble to handle one or more client classes,
creating objects of the sub-classes from yaml,
keeping track of the created object in dictionaries keyed by name,
writing the current content of the factory to a yaml file.
- add_dict(configurable_class)[source]
Add a dictionary for one of the client classes
- Return type:
dict[str,TypeVar(C, bound= Configurable)]- 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)[source]
Add an object one of ‘C’ client class to the corresponding dict
- Return type:
None- Parameters:
the_object (C) – Object in question
Notes
This should be called by the factory when inserting objects of the client classes
-
client_classes:
list[type[Configurable]]
- classmethod instance()[source]
Return the singleton instance of the factory
- Return type:
TypeVar(T, bound= RailFactoryMixin)
- load_instance_yaml(yaml_file)[source]
Read a yaml file and load the factory accordingly
- Return type:
None- Parameters:
yaml_file (str) – File to read
Notes
See class description for yaml file syntax
- load_instance_yaml_tag(yaml_config, from_file)[source]
Read a yaml tag and load the factory accordingy
- Return type:
None- Parameters:
yaml_config (list[dict[str, Any]]) – Yaml tag to load
from_file (str) – File it was loaded from, used to aviod reloading
Notes
See class description for yaml file syntax
- load_object_from_yaml_tag(configurable_class, yaml_tag)[source]
Create and add an object of one of the client classes from a yaml tag
- Return type:
None- Parameters:
configurable_class (type[C]) – Client class in question
yaml_tag (dict[str, Any]) – Yaml used to create the object
- classmethod load_yaml(yaml_file)[source]
Load a yaml file
- Return type:
None- Parameters:
yaml_file (str) – File to read and load
Notes
See class helpstring for yaml format
- classmethod load_yaml_tag(yaml_config, from_file)[source]
Load from a yaml tag
- Return type:
None- Parameters:
yaml_config (list[dict[str, Any]]) – Yaml tag used to load
from_file (str) – File it was loaded from, used to aviod reloading
Notes
See class helpstring for yaml format
- to_instance_yaml_dict()[source]
Write the content of the factory to a dict for export to a yaml file
- Return type:
dict
- classmethod to_yaml_dict()[source]
Construct a dictionary to write to a yaml file
- Return type:
dict
- classmethod write_yaml(yaml_file)[source]
Write to a yaml file
- Return type:
None- Parameters:
yaml_file (str) – Yaml file to write
Notes
See class helpstring for yaml format
-
yaml_tag:
str= ''