Class: Dry::Schema::MessageSet
- Inherits:
-
Object
- Object
- Dry::Schema::MessageSet
- Includes:
- Extensions::Hints::MessageSetMethods, Enumerable
- Defined in:
- lib/dry/schema/message_set.rb
Overview
A set of messages used to generate errors
Instance Attribute Summary collapse
-
#messages ⇒ Array<Message>
readonly
A list of compiled message objects.
-
#options ⇒ Hash
readonly
Options hash.
Attributes included from Extensions::Hints::MessageSetMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#[](key) ⇒ Array<String>
Get a list of message texts for the given key.
-
#each(&block) ⇒ Array
Iterate over messages.
-
#empty? ⇒ Boolean
Check if a message set is empty.
-
#fetch(key) ⇒ Array<String>
Get a list of message texts for the given key.
- #freeze ⇒ Object private
-
#initialize(messages, options = EMPTY_HASH) ⇒ MessageSet
constructor
private
A new instance of MessageSet.
-
#to_h ⇒ Hash<Symbol=>Array<String>>
(also: #to_hash)
Dump message set to a hash.
Constructor Details
#initialize(messages, options = EMPTY_HASH) ⇒ MessageSet
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of MessageSet.
32 33 34 35 |
# File 'lib/dry/schema/message_set.rb', line 32 def initialize(, = EMPTY_HASH) @messages = @options = end |
Instance Attribute Details
#messages ⇒ Array<Message> (readonly)
A list of compiled message objects
19 20 21 |
# File 'lib/dry/schema/message_set.rb', line 19 def @messages end |
#options ⇒ Hash (readonly)
Options hash
24 25 26 |
# File 'lib/dry/schema/message_set.rb', line 24 def @options end |
Class Method Details
.[](messages, options = EMPTY_HASH) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 |
# File 'lib/dry/schema/message_set.rb', line 27 def self.[](, = EMPTY_HASH) new(.flatten, ) end |
Instance Method Details
#[](key) ⇒ Array<String>
Get a list of message texts for the given key
71 72 73 |
# File 'lib/dry/schema/message_set.rb', line 71 def [](key) to_h[key] end |
#each(&block) ⇒ Array
Iterate over messages
47 48 49 50 51 52 |
# File 'lib/dry/schema/message_set.rb', line 47 def each(&block) return self if empty? return to_enum unless block .each(&block) end |
#empty? ⇒ Boolean
Check if a message set is empty
93 94 95 |
# File 'lib/dry/schema/message_set.rb', line 93 def empty? @empty ||= .empty? end |
#fetch(key) ⇒ Array<String>
Get a list of message texts for the given key
84 85 86 |
# File 'lib/dry/schema/message_set.rb', line 84 def fetch(key) self[key] || raise(KeyError, "+#{key}+ message was not found") end |
#freeze ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
98 99 100 101 102 |
# File 'lib/dry/schema/message_set.rb', line 98 def freeze to_h empty? super end |
#to_h ⇒ Hash<Symbol=>Array<String>> Also known as: to_hash
Dump message set to a hash
59 60 61 |
# File 'lib/dry/schema/message_set.rb', line 59 def to_h @to_h ||= end |