ClarityPrintLogic

struct ClarityPrintLogic : ClarityPrintHelper

A struct that contains a method that formats and prints a message to the console corresponding to a single print number from correlated data collated by MessageCollator.

The struct conforms to the ClarityPrintHelper protocol. The protocol groups default implementations of print logic helper methods in an extension.

  • A method that formats and prints a message to the console corresponding to data stored as JSON for a given print number. This method acts as the single internal call point for the public Clarity print overloads.

    There are four main task phases to the method:

    1. Run ‘Guard return without further action’ conditions:
      • Guard that the SettingsManagerService instance from the used Bundle is not nil.
      • Guard assign a settings instance either from the settings parameter argument or from the used Bundle.
      • Guard that the FormattingManagerService instance from the used Bundle is not nil.
      • Guard assign an instance of the message to print for the print number instance from the shared dictionary of all Message instances keyed by print number from MessageCollator. If there is no message for the key or no key print an alert before returning.
    2. Resolve whether to print the message based on user preferences in settings. If the result is false return without further action.
    3. Compile the print number message string(s) based on the data provided.
    4. Print the message and any additional values provided.

    Note

    The print overloads would never provide arguments to both functionName and values in a single call.

    PrintType will be set for an .event when an effect string is required despite .Effect being a valid PrintType. This anomoly is caused because it is the only occurrence when two different PrintTypes require evaluation for the same print call. This is solved by the inout return of a flag from the string compilation helper method.

    Declaration

    Swift

    internal func printLogic(_ printNumber: Int, _ settings: SettingsManagerService?, _ functionName: String? = nil, _ values: Any? = nil)

    Parameters

    printNumber

    A unique number used as a key to access a specific associated message from a dictionary containing all message data.

    settings

    An optional parameter for a mock SettingsManagerService instance. The mock SettingsManagerService instance can have its properties set programmatically to a variety of values. This enables more convenient and dynamic evaluation of a wider range of unit tests in a test target than is possible when using the JSON access mechanism.

    functionName

    An optional String the function name derived from a #function macro argument provided to the relevant public Clarity print overloads. If this parameter is included Clarity formats and prints the log as a function call node for the function that contains printNumber.

    values

    An optional parameter for the inclusion of variable values to be printed as part of the message. If this parameter is included Clarity formats and prints the log as a value report node. The parameter can be a single value of any type, a Collection of any type or an instance conforming to the Error protocol.