- Parent Namespace
- SleepingKingStudios::Tools::Assertions
- Inherited Classes
- SleepingKingStudios::Tools::Messages::Strategies::HashStrategy
>
SleepingKingStudios::Tools::Messages::Strategy
>
Object
- Defined In
- lib/sleeping_king_studios/tools/assertions/messages_strategy.rb
Table Of Contents
Overview
Messages strategy for displaying assertions errors.
Defines its own internal message templates, and automatically handles value
name option (:as option) when generating messages.
Back To Top
Constants
ERROR_MESSAGES
= {
'blank' =>
'must be nil or empty',
'block' =>
'block returned a falsy value',
'boolean' =>
'must be true or false',
'class' =>
'is not a Class',
'class_or_module' =>
'is not a Class or Module',
'exclusion' =>
'is one of %s',
'exclusion_range' =>
'is within %s',
'inclusion' =>
'is not one of %s',
'inclusion_range' =>
'is outside %s',
'inherit_from' =>
'does not inherit from %s',
'instance_of' =>
'is not an instance of %s',
'instance_of_anonymous' =>
'is not an instance of %s (%s)',
'matches' =>
'does not match the expected value',
'matches_proc' =>
'does not match the Proc',
'matches_regexp' =>
'does not match the pattern %s',
'name' =>
'is not a String or a Symbol',
'nil' =>
'must be nil',
'not_nil' =>
'must not be nil',
# @note: This value will be changed in a future version.
'presence' =>
"can't be blank"
}.freeze</code></span>
rubocop:disable Layout/HashAlignment
Back To Top
Constructor
#initialize => MessagesStrategy
rubocop:enable Layout/HashAlignment
Returns
- (MessagesStrategy) — a new instance of MessagesStrategy
Back To Top
Instance Attributes
#templates => Hash (readonly)
- Inherited From
- SleepingKingStudios::Tools::Messages::Strategies::HashStrategy
Returns
- (Hash) — the templates used to generate messages.
Back To Top
Instance Methods
#call(key, parameters: {}, scope: nil, **options) => String
- Inherited From
- SleepingKingStudios::Tools::Messages::Strategy
Generates a formatted string for the given key, parameters, and options.
Parameters
- key (String, Symbol) — the key used to resolve the message.
- parameters (Hash) — the parameters used to generate the message,
such as values for a template string.
- scope (String) — the namespace for the key. Combined with the given
key to generate the scoped key value.
- options (Hash) — additional options for resolving or generating the
message.
Returns
- (String) — the generated template string, or a generic error
string if a message is not defined for the given key and parameters.
Back To Top
Back to
Documentation |
Reference
|
SleepingKingStudios
|
SleepingKingStudios::Tools
|
SleepingKingStudios::Tools::Assertions