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:
- 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.
- Resolve whether to print the message based on user preferences in
settings
. If the result isfalse
return without further action. - Compile the print number message string(s) based on the data provided.
- Print the message and any additional values provided.
Note
The print overloads would never provide arguments to both
functionName
andvalues
in a single call.PrintType
will be set for an.event
when an effect string is required despite.Effect
being a validPrintType
. This anomoly is caused because it is the only occurrence when two differentPrintType
s require evaluation for the same print call. This is solved by theinout
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 containsprintNumber
.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 theError
protocol. - Run ‘Guard return without further action’ conditions: