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 ⇒ Object readonly
- #options ⇒ Object readonly
- #placeholders ⇒ Object readonly
Attributes included from Extensions::Hints::MessageSetMethods
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean private
- #fetch(key) ⇒ Object
-
#initialize(messages, options = EMPTY_HASH) ⇒ MessageSet
constructor
private
A new instance of MessageSet.
- #to_h ⇒ Object (also: #to_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.
24 25 26 27 28 |
# File 'lib/dry/schema/message_set.rb', line 24 def initialize(, = EMPTY_HASH) @messages = @options = initialize_placeholders! end |
Instance Attribute Details
#messages ⇒ Object (readonly)
16 17 18 |
# File 'lib/dry/schema/message_set.rb', line 16 def @messages end |
#options ⇒ Object (readonly)
16 17 18 |
# File 'lib/dry/schema/message_set.rb', line 16 def @options end |
#placeholders ⇒ Object (readonly)
16 17 18 |
# File 'lib/dry/schema/message_set.rb', line 16 def placeholders @placeholders 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.
19 20 21 |
# File 'lib/dry/schema/message_set.rb', line 19 def self.[](, = EMPTY_HASH) new(.flatten, ) end |
Instance Method Details
#[](key) ⇒ Object
43 44 45 |
# File 'lib/dry/schema/message_set.rb', line 43 def [](key) to_h[key] end |
#each(&block) ⇒ Object
31 32 33 34 |
# File 'lib/dry/schema/message_set.rb', line 31 def each(&block) return to_enum unless block .each(&block) end |
#empty? ⇒ Boolean
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.
53 54 55 |
# File 'lib/dry/schema/message_set.rb', line 53 def empty? .empty? end |
#fetch(key) ⇒ Object
48 49 50 |
# File 'lib/dry/schema/message_set.rb', line 48 def fetch(key) self[key] || raise(KeyError, "+#{key}+ message was not found") end |
#to_h ⇒ Object Also known as: to_hash
37 38 39 |
# File 'lib/dry/schema/message_set.rb', line 37 def to_h end |