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.
30 31 32 33 |
# File 'lib/dry/schema/message_set.rb', line 30 def initialize(, = EMPTY_HASH) @messages = @options = end |
Instance Attribute Details
#messages ⇒ Array<Message> (readonly)
A list of compiled message objects
17 18 19 |
# File 'lib/dry/schema/message_set.rb', line 17 def @messages end |
#options ⇒ Hash (readonly)
Options hash
22 23 24 |
# File 'lib/dry/schema/message_set.rb', line 22 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.
25 26 27 |
# File 'lib/dry/schema/message_set.rb', line 25 def self.[](, = EMPTY_HASH) new(.flatten, ) end |
Instance Method Details
#[](key) ⇒ Array<String>
Get a list of message texts for the given key
69 70 71 |
# File 'lib/dry/schema/message_set.rb', line 69 def [](key) to_h[key] end |
#each(&block) ⇒ Array
Iterate over messages
45 46 47 48 49 50 |
# File 'lib/dry/schema/message_set.rb', line 45 def each(&block) return self if empty? return to_enum unless block .each(&block) end |
#empty? ⇒ Boolean
Check if a message set is empty
91 92 93 |
# File 'lib/dry/schema/message_set.rb', line 91 def empty? @empty ||= .empty? end |
#fetch(key) ⇒ Array<String>
Get a list of message texts for the given key
82 83 84 |
# File 'lib/dry/schema/message_set.rb', line 82 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.
96 97 98 99 100 |
# File 'lib/dry/schema/message_set.rb', line 96 def freeze to_h empty? super end |
#to_h ⇒ Hash<Symbol=>Array<String>> Also known as: to_hash
Dump message set to a hash
57 58 59 |
# File 'lib/dry/schema/message_set.rb', line 57 def to_h @to_h ||= end |