Class: Dry::Validation::MessageSet
- Inherits:
-
Object
- Object
- Dry::Validation::MessageSet
- Includes:
- Enumerable
- Defined in:
- lib/dry/validation/message_set.rb
Constant Summary collapse
- HINT_EXCLUSION =
%i( key? filled? none? bool? str? int? float? decimal? date? date_time? time? hash? array? format? ).freeze
Instance Attribute Summary collapse
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#hints ⇒ Object
readonly
Returns the value of attribute hints.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#placeholders ⇒ Object
readonly
Returns the value of attribute placeholders.
Class Method Summary collapse
Instance Method Summary collapse
- #dump ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #failures? ⇒ Boolean
-
#initialize(messages, options = EMPTY_HASH) ⇒ MessageSet
constructor
A new instance of MessageSet.
- #root? ⇒ Boolean
- #to_a ⇒ Object
- #to_h ⇒ Object (also: #to_hash)
Constructor Details
#initialize(messages, options = EMPTY_HASH) ⇒ MessageSet
Returns a new instance of MessageSet.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dry/validation/message_set.rb', line 19 def initialize(, = EMPTY_HASH) @messages = @hints = .select(&:hint?) @failures = - hints @paths = failures.map(&:path).uniq @options = initialize_hints! initialize_placeholders! end |
Instance Attribute Details
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
13 14 15 |
# File 'lib/dry/validation/message_set.rb', line 13 def failures @failures end |
#hints ⇒ Object (readonly)
Returns the value of attribute hints.
13 14 15 |
# File 'lib/dry/validation/message_set.rb', line 13 def hints @hints end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
13 14 15 |
# File 'lib/dry/validation/message_set.rb', line 13 def @messages end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/dry/validation/message_set.rb', line 13 def @options end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
13 14 15 |
# File 'lib/dry/validation/message_set.rb', line 13 def paths @paths end |
#placeholders ⇒ Object (readonly)
Returns the value of attribute placeholders.
13 14 15 |
# File 'lib/dry/validation/message_set.rb', line 13 def placeholders @placeholders end |
Class Method Details
.[](messages, options = EMPTY_HASH) ⇒ Object
15 16 17 |
# File 'lib/dry/validation/message_set.rb', line 15 def self.[](, = EMPTY_HASH) new(.flatten, ) end |
Instance Method Details
#dump ⇒ Object
30 31 32 |
# File 'lib/dry/validation/message_set.rb', line 30 def dump root? ? to_a : to_h end |
#each(&block) ⇒ Object
46 47 48 49 |
# File 'lib/dry/validation/message_set.rb', line 46 def each(&block) return to_enum unless block .each(&block) end |
#empty? ⇒ Boolean
38 39 40 |
# File 'lib/dry/validation/message_set.rb', line 38 def empty? .empty? end |
#failures? ⇒ Boolean
34 35 36 |
# File 'lib/dry/validation/message_set.rb', line 34 def failures? [:failures].equal?(true) end |
#root? ⇒ Boolean
42 43 44 |
# File 'lib/dry/validation/message_set.rb', line 42 def root? !empty? && failures.all?(&:root?) end |
#to_a ⇒ Object
60 61 62 |
# File 'lib/dry/validation/message_set.rb', line 60 def to_a to_h.values.flatten end |
#to_h ⇒ Object Also known as: to_hash
51 52 53 54 55 56 57 |
# File 'lib/dry/validation/message_set.rb', line 51 def to_h if root? { nil => failures.map(&:to_s) } else failures? ? : hints_map end end |