Class: Dry::Schema::MessageSet

Inherits:
Object
  • Object
show all
Includes:
Extensions::Hints::MessageSetMethods, Enumerable
Defined in:
lib/dry/schema/message_set.rb

Overview

A set of messages used to generate errors

See Also:

Instance Attribute Summary collapse

Attributes included from Extensions::Hints::MessageSetMethods

#failures, #hints

Class Method Summary collapse

Instance Method Summary collapse

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(messages, options = EMPTY_HASH)
  @messages = messages
  @options = options
  initialize_placeholders!
end

Instance Attribute Details

#messagesObject (readonly)



16
17
18
# File 'lib/dry/schema/message_set.rb', line 16

def messages
  @messages
end

#optionsObject (readonly)



16
17
18
# File 'lib/dry/schema/message_set.rb', line 16

def options
  @options
end

#placeholdersObject (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.[](messages, options = EMPTY_HASH)
  new(messages.flatten, options)
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
  messages.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.

Returns:

  • (Boolean)


53
54
55
# File 'lib/dry/schema/message_set.rb', line 53

def empty?
  messages.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_hObject Also known as: to_hash



37
38
39
# File 'lib/dry/schema/message_set.rb', line 37

def to_h
  messages_map
end